问题
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.
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/51205469/multiple-jars-of-same-groupid-and-artifactid-in-web-inf