There are four duplicate classes in two Maven artifacts from Apache: commons-beanutils:commons-beanutils:1.8.3
and commons-collections:commons-collections:3.2.1
:
org.apache.commons.collections.ArrayStack
org.apache.commons.collections.Buffer
org.apache.commons.collections.BufferUnderflowException
org.apache.commons.collections.FastHashMap
Is it possible to replace one of them with some other artifact to avoid this duplication? I tried to google but didn't find any solution. Rather annoying problem.
In this case, the problem isn't maven or exclusions (which usually is the issue) but you are using the wrong version of beanutils most likely.
There is a version of the beanutils jar that has bean collections included and one that does not. The maven dependencies for the beanutils with bean collections includes commons collections. If you are using commons collections yourself, use the core version of and include commons collections in the maven dependencies.
This is where it is explained a bit: http://commons.apache.org/beanutils/
That page says this:
commons-beanutils.jar - contains everything
commons-beanutils-core.jar - excludes Bean Collections classes
commons-beanutils-bean-collections.jar - only Bean Collections classes
The main commons-beanutils.jar has an optional dependency on Commons Collections
Look at this article link it's tells to use exclude tag
UPDATE
look at this to link2
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>classworlds:classworlds</exclude>
<exclude>junit:junit</exclude>
<exclude>jmock:*</exclude>
<exclude>*:xml-apis</exclude>
<exclude>org.apache.maven:lib:tests</exclude>
<exclude>log4j:log4j:jar:</exclude>
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
So basically what's happening is you're pulling in two versions either from a misconfigured jar (pulls in both, which is redundant), or from multiple dependencies where one pulls in one version, the other the other, collision! I'd call that a "weird release system" problem of the commons-beanutils, as it were, since maven doesn't handle that pattern easily...a fix for me was to bump the version of my dependency that pulls in both versions (in my case "commons-configuration"), or to manually specify a particular version of commons-configuration
:
So this mvn dependency:tree
:
[INFO] +- commons-configuration:commons-configuration:jar:1.6:compile
[INFO] | +- commons-collections:commons-collections:jar:3.2.1:compile (version managed from 3.2)
[INFO] | +- commons-digester:commons-digester:jar:1.8:compile
[INFO] | \- commons-beanutils:commons-beanutils:jar:1.7.0:compile
[INFO] | \- commons-beanutils:commons-beanutils-core:jar:1.8.0:compile
became this:
[INFO] +- commons-configuration:commons-configuration:jar:1.7:compile
[INFO] | +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] | +- commons-lang:commons-lang:jar:2.6:compile
[INFO] | +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] | +- commons-digester:commons-digester:jar:1.8.1:compile
[INFO] | \- commons-beanutils:commons-beanutils:jar:1.8.3:compile
though according to the comments on the other answer, bumping "something" to a version that uses commons-beanutil 1.9+ would also do it.
Exclude the collection package from the beanutils JAR, it worked for me :)