This rule requires that the version for each dependency resolved during a build, is equal to or higher than all transitive dependency declarations. 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 the Maven site.
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>
Because the project will run logback-classic 0.9.9 with slf4j-api 1.4.0 and slf4j-api 1.4.0 is probably not forwards compatible with slf4j-api 1.5.0.
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 ]
And this will succeed.
<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 setup to use this rule
<project> ... <build> <plugins> ... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>3.4.1</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</excludedScopes> </excludedScopes> --> </requireUpperBoundDeps> </rules> </configuration> <goals> <goal>enforce</goal> </goals> </execution> </executions> </plugin> ... </plugins> </build> ... </project>