This rule requires that the version for each dependency resolved during a build is equal to or higher than highest version found in the transitive dependencies. The version of each dependency resolved during the build will normally be the version specified in the POM or the version with the least transitive steps (the "nearest" definition). For more information about Maven dependency resolution, see Introduction to the Dependency Mechanism.
The following parameters are supported by this rule:
- uniqueVersions - if SNAPSHOTs should be compared by their timestamped version or not. Default:
false
- excludes - specify the dependencies that will be ignored. The format is
groupId[:artifactId]
- includes - specify the dependencies that will be checked. If not empty only these will be checked. The format is
groupId[:artifactId]
- excludedScopes - a list of dependency scope which will be excluded. Default:
test
,provided
Here is a concrete example. This will cause a build to fail:
<dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.4.0</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>0.9.9</version> <!-- Depends on org.slf4j:slf4j-api:1.5.0 --> </dependency> </dependencies>
Here the build fails because slf4j-api 1.4.0 is added to the classpath, but logback-classic depends on the higher 1.5.0 version of slf4j-api.
This is the log message:
Failed while enforcing RequireUpperBoundDeps. The error(s) are [ RequireUpperBoundDeps error for org.slf4j:slf4j-api:1.4.0. Paths to dependency are: +-test:TestParent:1.0-SNAPSHOT +-org.slf4j:slf4j-api:1.4.0 and +-test:TestParent:1.0-SNAPSHOT +-ch.qos.logback:logback-classic:0.9.9 +-org.slf4j:slf4j-api:1.5.0 ]
This will succeed because the highest version, 1.6.0, is selected:
<dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.6.0</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>0.9.9</version> <!-- Depends on org.slf4j:slf4j-api:1.5.0 --> </dependency> </dependencies>
Here is how a project should be set up to use this rule:
<project> ... <build> <plugins> ... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>3.6.0</version> <executions> <execution> <id>enforce</id> <configuration> <rules> <requireUpperBoundDeps> <!-- 'uniqueVersions' (default:false) can be set to true if you want to compare the timestamped SNAPSHOTs --> <!-- <uniqueVersions>true</uniqueVersions> --> <!-- If you wish to ignore certain cases: <excludes> <exclude>com.google.guava:guava</exclude> </excludes> --> <!-- If you include specific cases only these will be checked: (when omitted everything is included) <includes> <include>com.google.guava:guava</include> </includes> --> <!-- only artifacts with provided scope will be excluded <excludedScopes> <excludedScope>provided</excludedScope> </excludedScopes> --> </requireUpperBoundDeps> </rules> </configuration> <goals> <goal>enforce</goal> </goals> </execution> </executions> </plugin> ... </plugins> </build> ... </project>