I'm using maven to build project.
It uses some lib A
, which in turn uses lib B_v2
.
However when I do mvn dependency:tree
I see that lib B v1
is used. I don't want this to happen cause now when I run I have a combination of lib A
+ B_v1
which were never tested.
Obviously this is because some another artifact wins when lib versions are resolved and B_v1
was used.
I want to know which artifact "won" and forces B_v1
to be used (so I can fix this artifact to use B_v2
too)
It must be one of the artifacts from mvn dependency:tree
but there are a lot of them there.
This is the strategy used by Maven for dependency resolution, as described in Introduction to the Dependency Mechanism :
Dependency mediation - this determines what version of an artifact will be chosen when multiple versions are encountered as dependencies. Maven picks the "nearest definition". That is, it uses the version of the closest dependency to your project in the tree of dependencies. You can always guarantee a version by declaring it explicitly in your project's POM. Note that if two dependency versions are at the same depth in the dependency tree, the first declaration wins.
- "nearest definition" means that the version used will be the closest one to your project in the tree of dependencies. For example, if dependencies for A, B, and C are defined as A -> B -> C -> D 2.0 and A -> E -> D 1.0, then D 1.0 will be used when building A because the path from A to D through E is shorter. You could explicitly add a dependency to D 2.0 in A to force the use of D 2.0.
By default mvn dependency:tree
does not list the dependencies that are omitted due to conflicting versions, so as long as B
has the same groupId
and artifactId
in v1
and v2
, it should appear only once: the artifact that "won". (You can see all the omitted dependencies, marked as such, by using mvn dependency:tree -Dverbose
.)