Consider the following Maven project, having a parent and two modules.
parent
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<modules>
<module>module1</module>
<module>module2</module>
</modules>
</project>
module1
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>module1</artifactId>
<parent>
<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<version>3.1.4.Final</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>3.3.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>module2</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
module2
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>module2</artifactId>
<parent>
<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<version>2.0.2</version>
</dependency>
</dependencies>
</project>
Module 1 has a dependency on weld-se-core, which in turn has a dependency on jakarta.enterprise.cdi-api. Module 2 has itself a dependency on jakarta.enterprise.cdi-api. Furthermore, module 1 has dependencies to junit-jupiter and mockito-junit-jupiter, both of which have a dependency on junit-jupiter-api, but unfortunately in different versions. Please consider this as an example. In my real project this is some private third-party dependency with a much larger dependency-tree, which neither can nor want to change.
As both modules are under my control, I want to make sure that when weld-se-core is updated in module 1, jakarta.enterprise.cdi-api in module 2 is updated accordingly. I tried using the maven-enforcer-plugin with the following rules
<dependencyConvergence/>
<requireSameVersions>
<dependencies>
<dependency>jakarta.enterprise:jakarta.enterprise.cdi-api</dependency>
</dependencies>
</requireSameVersions>
Problem is: requireSameVersions does not break the build, when the versions of jakarta.enterprise.cdi-api don't match while dependencyConvergence shows me all errors, not only the one concerning jakarta.enterprise.cdi-api.
The message when using the dependencyConvergence rule is as follows (abbreviated)
[INFO] --- maven-enforcer-plugin:3.0.0-M3:enforce (enforce-cdi-same-version) @ module1 ---
[WARNING]
Dependency convergence error for jakarta.enterprise:jakarta.enterprise.cdi-api:2.0.2 paths to dependency are:
[...]
+-com.example:module1:0.0.1-SNAPSHOT
+-org.jboss.weld.se:weld-se-core:3.1.4.Final
+-jakarta.enterprise:jakarta.enterprise.cdi-api:2.0.2
and
+-com.example:module1:0.0.1-SNAPSHOT
+-com.example:module2:0.0.1-SNAPSHOT
+-jakarta.enterprise:jakarta.enterprise.cdi-api:2.0.1
[WARNING]
Dependency convergence error for org.junit.jupiter:junit-jupiter-api:5.6.2 paths to dependency are:
[...]
+-com.example:module1:0.0.1-SNAPSHOT
+-org.junit.jupiter:junit-jupiter:5.6.2
+-org.junit.jupiter:junit-jupiter-engine:5.6.2
+-org.junit.jupiter:junit-jupiter-api:5.6.2
and
+-com.example:module1:0.0.1-SNAPSHOT
+-org.mockito:mockito-junit-jupiter:3.3.3
+-org.junit.jupiter:junit-jupiter-api:5.4.2
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.DependencyConvergence failed with message:
Failed while enforcing releasability. See above detailed error message.
The first Warning is wanted, the second one is unwanted.
Question: Is there any way to ensure dependency convergence only for a specific set of dependencies?