When building the project with Maven I get 2 jars in my target dir:
aopalliance-aopalliance-1.0.jar
org.aopalliance-aopalliance-1.0.jar
I suspect the following dependency in my pom.xml is the one responsible
<dependency>
<groupId>org.aopalliance</groupId>
<artifactId>aopalliance</artifactId>
<version>1.0</version>
</dependency>
but I don’t understand why this happens. I have a bunch of other dependencies in my pom.xml that are defined in the same way, and the JAR in question is installed in the Nexus just like the other JAR’s, but the other dependencies do not result in JAR’s in my target dir.
Thanks.
In the light of this answer, it is assumed you use some kind of plugin like the Maven Assembly plugin or Maven EAR plugin to copy all the project’s dependencies to your target folder.
It is highly likely that some dependency like Guice is pulling in the
aopalliance:aopallianceartifact (groupId:artifactId notation), whereas you just added a dependency onorg.aopalliance:aopalliance. Maven doesn’t know that it just added the same class files twice – it checks the groupId and artifactId to see whether two jars are (supposedly) different.You have two options:
Remove the dependency in your poms, or change the groupId to
aopalliance.Trace where the
aopalliancedependency is coming from, then exclude theaopallianceartifact from the problematic artifacts’ transitive dependencies.You can do (2) by running
mvn dependency:tree, or with the M2Eclipse plugin by opening your POM and looking at the Dependency Hierarchy tab. Here’s some sample output of the dependency:tree command:Take a look at commons-logging for example, we can see that the axis:axis library depends on it.
Once you know which library depends on
aopalliance, you can add an exclusion in the POM. It would be preferred if you keep this exclusion and the declaration of theorg.aopalliancedependency in the same POM.