Reputation: 37
In my Maven project, I have the following dependency:
<dependency>
<groupId>com.projectA</groupId>
<artifactId>projectA</artifactId>
<version>1.10.0</version>
<type>pom</type>
</dependency>
This dependency includes a transitive dependency on projectB version 2.2.0.
Additionally, I have another direct dependency on an older version of the same library:
<dependency>
<groupId>com.projectB</groupId>
<artifactId>projectB</artifactId>
<version>2.1.0</version>
</dependency>
How can I ensure that my project fails to compile if an older version (e.g., 2.1.0) of projectB is used, and always enforces version with is used by projectA?
I want to prevent the project from accidentally using a lower version of the projectB dependency.
Thanks for your help!
Upvotes: 0
Views: 64
Reputation: 35853
You can use the requireUpperBoundDeps rule of the Maven enforcer plugin:
https://maven.apache.org/enforcer/enforcer-rules/requireUpperBoundDeps.html
which is made for situations like this.
Upvotes: 1