Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Maven resolve dependency conflicts?

Tags:

maven

Let's assume we have a Project A.

  • Project A has a dependency on Project B version 1.0
  • Project A has a dependency on Project C version 2.0
  • Project C (version 2.0) has a dependency on Project B version 2.0

In this case, how would Maven resolve the conflict?

like image 546
erolkaya84 Avatar asked Apr 06 '26 18:04

erolkaya84


2 Answers

I found this explanation and it was really helpful to me.

Nearest definition means that the version used will be the closest one to your project in the tree of dependencies,

eg. 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

like image 96
erolkaya84 Avatar answered Apr 08 '26 08:04

erolkaya84


It'd build with Project B v 1.0

You can use http://maven.apache.org/plugins/maven-dependency-plugin/examples/resolving-conflicts-using-the-dependency-tree.html to see, that it omitted B 2.0 cause 1.0 is nearer.

from page above:

by default Maven resolves version conflicts with a nearest-wins strategy.

Output'd be something like that:

[INFO] [dependency:tree]
[INFO] Project A
[INFO] +- Project-B:jar:1.0:compile
[INFO] \- Project-C:jar:2.0:compile
[INFO]    \- (Project-B:jar:2.0:compile - ommited for conflicts with 1.0)
like image 36
Nickname0222022022 Avatar answered Apr 08 '26 08:04

Nickname0222022022



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!