1
votes

I am using maven version 3.5.3 and while building my project, I am getting two versions of apache commons-lang3 in my WEB-INF (v3.1 and v3.4) even when I have explicitly specified v.3.4 in my "dependency-management" of my parent pom.xml.

Both have the same groupId and artifactId.

I am confused. Is this expected behavior of maven? Under what circumstances does this happen? I was under the impression that maven resolves all dependencies to only one jar if dependencies have same groupId and artifactId.

2
v3.1 is coming by being indirectly referenced from a specific reference. On some IDE you have the possibility to see the entire 'Dependency Hierarchy'. Or through the prompt you can run 'mvn dependency:tree' to see it there is any reference to v3.1Tiago Mussi

2 Answers

1
votes

I am confused. Is this expected behavior of maven? Under what circumstances does this happen? I was under the impression that maven resolves all dependencies to only one jar if dependencies have same groupId and artifactId.

And Maven does.
For a same groupId and a same artifactId, the default behavior of a Maven package goal is packaging only one version of them. Note that if multiple versions are available, the chosen version by Maven is not really predictable.

I imagine that at a time your build performs a manual copy from the jar into the WEB-INF folder (via a Maven plugin for example), or your pom (or a parent of) specifies an overlay in the WAR.

The mvn dependency:tree command should help you to understand where the distinct versions are referenced or pulled.

1
votes

I saw this problem several times when builds were done without "clean", i.e. using package instead of clean package. In this case, you may get a mixture of old and recent builds.