-
Notifications
You must be signed in to change notification settings - Fork 78
Linkage Checker Enforcer Rule
The Linkage Checker Enforcer Rule verifies that the transitive dependency tree of pom.xml does not have
any linkage errors.
Add the following plugin configuration to your pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M3</version>
<dependencies>
<dependency>
<groupId>com.google.cloud.tools</groupId>
<artifactId>linkage-checker-enforcer-rules</artifactId>
<version>1.1.4</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>enforce-linkage-checker</id>
<!-- Important! Should run after compile -->
<phase>verify</phase>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<LinkageCheckerRule
implementation="com.google.cloud.tools.dependencies.enforcer.LinkageCheckerRule"/>
</rules>
</configuration>
</execution>
</executions>
</plugin>
...For a BOM project, set dependencySection element to DEPENDENCY_MANAGEMENT.
<LinkageCheckerRule
implementation="com.google.cloud.tools.dependencies.enforcer.LinkageCheckerRule">
<dependencySection>DEPENDENCY_MANAGEMENT</dependencySection>
</LinkageCheckerRule>To suppress linkage errors that are not reachable in the class reference graph from the classes in the direct
dependencies of the project, set reportOnlyReachable element to true. (default: false).
<LinkageCheckerRule
implementation="com.google.cloud.tools.dependencies.enforcer.LinkageCheckerRule">
<reportOnlyReachable>true</reportOnlyReachable>
</LinkageCheckerRule>To suppress linkage errors using Linkage Checker Exclusion File, set exclusionFile element to the exclusion file.
<LinkageCheckerRule
implementation="com.google.cloud.tools.dependencies.enforcer.LinkageCheckerRule">
<exclusionFilterFile>linkage-checker-exclusion-rules.xml</exclusionFilterFile>
</LinkageCheckerRule>If a violation should not fail the build, set the level element to WARN:
<LinkageCheckerRule
implementation="com.google.cloud.tools.dependencies.enforcer.LinkageCheckerRule">
<level>WARN</level>
</LinkageCheckerRule>The Linkage Checker Enforcer Rule is bound to the verify lifecycle:
$ mvn verify
Successful checks output no error.
[INFO] --- maven-enforcer-plugin:3.0.0-M3:enforce (enforce-linkage-checker) @ protobuf-java-util ---
[INFO] No error found
Failed checks output the missing classes, fields, or methods and the referencing classes.
[INFO] --- maven-enforcer-plugin:3.0.0-M3:enforce (enforce-linkage-checker) @ google-cloud-core-grpc ---
[ERROR] Linkage Checker rule found 21 reachable errors. Linkage error report:
Class org.eclipse.jetty.npn.NextProtoNego is not found;
referenced by 1 class file
io.grpc.netty.shaded.io.netty.handler.ssl.JettyNpnSslEngine (grpc-netty-shaded-1.23.0.jar)
...
The dependencySection element determines whether the rule checks the dependencies in
the dependencies section or the dependencyManagement section.
The following values are accepted:
-
DEPENDENCIES(default value): the rule checks the class path calculated from the project'sdependenciessection. -
DEPENDENCY_MANAGEMENT: the rule checks the class path calculated from the project'sdependencyManagementsection.