Matt C.
Matt C.

Reputation: 3320

How to ensure I am not including duplicate transitive dependencies through two maven dependencies?

I am looking for a way to test whether or not any of my explicit dependencies in my pom.xml reference/include any of the same transitive dependencies. For example, if dependency-A includes junit.jupiter and dependency-B also includes junit.jupiter, I want a way to see this so that I can exclude it from one of them to prevent conflicts.

I saw through this link that you can use mvn dependency:tree to essentially show all dependencies and their transitive dependencies, but it prints in a fairly unreadable format and it isn't clear through that output what the source of each transitive dependency is.

Upvotes: 0

Views: 765

Answers (1)

J Fabian Meier
J Fabian Meier

Reputation: 35903

Note that if dependency-A uses junit.jupiter and dependency-B uses junit.jupiter, then only one of these dependencies will be included. Maven will not include the same dependency twice.

What can be tricky, though, is the resulting version. Maven takes the "nearest" element, not the highest version. If you want to notice if you have conflicting versions, I recommend the "dependency convergence" rule of the maven enforcer rules.

If you want to choose one version for junit.jupiter, add an entry to <dependencyManagement> in your POM.

Upvotes: 2

Related Questions