I have specified a version of a library in imported dependencyManagement section of a parent pom. I confirmed that my effective pom has only one occurence of this dependency. It is in dependencyManagement section:
<dependencyManagement>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>[3.18.1-GA]</version>
</dependency>
</dependencyManagement>
That should override version for transitive dependencies depending on it. After installing (and reinstalling dependencies to match version bounds), org.apache.maven.plugins:maven-dependency-plugin:2.8:tree prints:
org.javassist:javassist:jar:3.18.1-GA:compile (version selected from constraint [3.18.1-GA,3.18.1-GA])
But (originally, without reinstalling dependencies) enforcer complains about wrong version:
[WARNING] Rule 1: org.apache.maven.plugins.enforcer.DependencyConvergence failed with message:
Failed while enforcing releasability the error(s) are [
Dependency convergence error for org.javassist:javassist:3.18.2-GA paths to dependency are:
...
And shows that first transitive dependency uses
org.javassist:javassist:3.18.2-GA
Which comes from dependency that in turn depends on:
<dependencies>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.18.2-GA</version>
</dependency>
</dependencies>
and another uses
org.javassist:javassist:3.18.1-GA
Why is enforcer inconsistent with dependency tree? What could be wrong? If I use version bounds, will they be respected and I can skip using enforcer for this purpose?
Also, adding dependency to project module in question does not change anything.
Tl;dr:
dependencyManagementoverrides the version of transitive dependenciesAll the credit for this answer goes to Andy Dennie whose blog post I stumbled upon:
https://www.fizz-buzz.com/blog/2012/08/02/maven-enforcer-plugin-vs-dependencymanagement
dependencyManagementdoes two things - one of which is well known and the other is rarely mentioned.So the enforcer plugin does not ignore the
dependencyManagement. But is unable to recognize the discrepancy since the transitive dependency's version was altered before it went to work. Andy Denny has a good suggestion on his blog on how to proceed:The trade-off here is that you have a working enforcer plugin that helps you with dependency hell, but have to do more by hand.