Question

I am getting a duplicated class error because of duplicated jars in my repository. Jars are coming with an open source Apache project's sub module's pom, project is James, sub module is container-spring.

Here is pom.xml in root of James:

http://svn.apache.org/repos/asf/james/server/tags/james-server-3.0-beta4/pom.xml

Here is sub module container-spring's pom.xml:

http://svn.apache.org/repos/asf/james/server/tags/james-server-3.0-beta4/container-spring/pom.xml

Was it helpful?

Solution

To answer your question i configured a simple maven project with the following pom.xml:

<project>
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.stackoverflow.tuxi</groupId>
  <artifactId>duplicatedjar</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <dependencies>
    <dependency>
      <groupId>org.apache.james</groupId>
      <artifactId>james-server</artifactId>
      <version>3.0-beta4</version>
      <type>pom</type>
    </dependency>
    <dependency>
      <groupId>org.apache.james</groupId>
      <artifactId>james-server-container-spring</artifactId>
      <version>3.0-beta4</version>
    </dependency>
  </dependencies>
</project>

And then executed the maven dependency tree command to analyse the dependencies:

% mvn dependency:tree                                                                                                                                                                                              
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building duplicatedjar 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ duplicatedjar ---
[INFO] com.stackoverflow.tuxi:duplicatedjar:jar:1.0-SNAPSHOT
[INFO] +- org.apache.james:james-server:pom:3.0-beta4:compile
[INFO] \- org.apache.james:james-server-container-spring:jar:3.0-beta4:compile
[INFO]    +- org.apache.james:james-server-lifecycle-spring:jar:3.0-beta4:compile
[INFO]    |  +- org.apache.geronimo.specs:geronimo-annotation_1.1_spec:jar:1.0.1:compile
[INFO]    |  \- org.apache.geronimo.specs:geronimo-jpa_2.0_spec:jar:1.0:compile
[INFO]    +- org.apache.james:james-server-lifecycle-api:jar:3.0-beta4:compile
[INFO]    +- org.apache.james:james-server-filesystem-api:jar:3.0-beta4:compile
[INFO]    |  +- org.apache.james:apache-jsieve-manager-api:jar:0.5:compile
[INFO]    |  \- commons-io:commons-io:jar:2.0.1:compile
[INFO]    +- org.apache.james:james-server-mailetcontainer-api:jar:3.0-beta4:compile
[INFO]    +- org.apache.james:james-server-protocols-library:jar:3.0-beta4:compile
[INFO]    |  +- org.apache.james:james-server-util:jar:3.0-beta4:compile
[INFO]    |  +- org.apache.james.protocols:protocols-netty:jar:1.6.2:compile
[INFO]    |  \- io.netty:netty:jar:3.3.1.Final:compile
[INFO]    +- org.apache.james:james-server-data-api:jar:3.0-beta4:compile
[INFO]    +- org.apache.james:james-server-core:jar:3.0-beta4:compile
[INFO]    |  \- org.apache.james:apache-mailet-base:jar:1.1:compile
[INFO]    +- org.apache.james:apache-james-mailbox-api:jar:0.4:compile
[INFO]    +- org.apache.james:apache-james-mailbox-tool:jar:0.4:compile
[INFO]    |  +- org.apache.james:apache-james-mailbox-store:jar:0.4:compile
[INFO]    |  |  +- org.apache.james:apache-mime4j-core:jar:0.7.2:compile
[INFO]    |  |  \- org.apache.james:apache-mime4j-dom:jar:0.7.2:compile
[INFO]    |  +- org.apache.james:apache-james-mailbox-memory:jar:0.4:compile
[INFO]    |  +- org.apache.geronimo.specs:geronimo-annotation_1.0_spec:jar:1.1.1:compile
[INFO]    |  \- org.apache.openjpa:openjpa:jar:2.1.0:compile
[INFO]    |     +- net.sourceforge.serp:serp:jar:1.13.1:compile
[INFO]    |     |  \- junit:junit:jar:3.8.1:compile
[INFO]    |     +- org.apache.geronimo.specs:geronimo-jms_1.1_spec:jar:1.1.1:compile
[INFO]    |     +- org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1.1:compile
[INFO]    |     \- commons-pool:commons-pool:jar:1.5.4:compile
[INFO]    +- org.apache.james.protocols:protocols-api:jar:1.6.2:compile
[INFO]    +- org.apache.james:apache-mailet:jar:2.4:compile
[INFO]    +- org.springframework:spring-core:jar:3.1.0.RELEASE:compile
[INFO]    |  +- org.springframework:spring-asm:jar:3.1.0.RELEASE:compile
[INFO]    |  \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO]    +- org.springframework:spring-beans:jar:3.1.0.RELEASE:compile
[INFO]    +- org.springframework:spring-context:jar:3.1.0.RELEASE:compile
[INFO]    |  +- org.springframework:spring-aop:jar:3.1.0.RELEASE:compile
[INFO]    |  \- org.springframework:spring-expression:jar:3.1.0.RELEASE:compile
[INFO]    +- org.springframework:spring-web:jar:3.1.0.RELEASE:compile
[INFO]    |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO]    +- org.springframework.osgi:spring-osgi-extender:jar:1.2.1:compile
[INFO]    |  +- org.springframework.osgi:spring-osgi-core:jar:1.2.1:compile
[INFO]    |  |  +- org.springframework:org.springframework.aop:jar:2.5.6.SEC01:compile
[INFO]    |  |  |  \- org.aopalliance:com.springsource.org.aopalliance:jar:1.0.0:compile
[INFO]    |  |  +- org.springframework:org.springframework.beans:jar:2.5.6.SEC01:compile
[INFO]    |  |  +- org.springframework:org.springframework.context:jar:2.5.6.SEC01:compile
[INFO]    |  |  \- org.springframework:org.springframework.core:jar:2.5.6.SEC01:compile
[INFO]    |  \- org.springframework.osgi:spring-osgi-io:jar:1.2.1:compile
[INFO]    +- org.osgi:org.osgi.core:jar:4.2.0:compile
[INFO]    +- commons-configuration:commons-configuration:jar:1.6:compile
[INFO]    |  +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO]    |  \- commons-lang:commons-lang:jar:2.4:compile
[INFO]    +- org.slf4j:slf4j-api:jar:1.6.1:compile
[INFO]    +- javax.mail:mail:jar:1.4.4:compile
[INFO]    \- log4j:log4j:jar:1.2.16:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.140s
[INFO] Finished at: Sun Sep 30 12:30:30 BRT 2012
[INFO] Final Memory: 12M/169M
[INFO] ------------------------------------------------------------------------

I don't know which jars in your project are conflicting with the ones above but I noticed that the spring dependency depends on the apache commons suite (the commons-xxx deps). A lot of projects use them (I.M.O. a lot of their stuff should be incorporated in the JDK itself, but thats another thread) but some commons libraries have some problems:

  • backward compability issues
  • the groupid and artifactid have changed along the years, so you can end up with equal jars with different names (commons-xxx and org.apache.commons.xxx)

Actually it is quite normal to have conflicting dependencies with the apache commons suite, so i am taking a guess here that it is your actual problem.

Normally the solution for this is declaring the apache commons libs that you need in your project directly in the dependencies and excluding the conflicting libraries also in the dependencies section, like @Vikdor said

You will end up with something probably like this (It is important to remove only the conflicting ones, not all of them like in the example below, or your software will not work correctly):

<project>
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.stackoverflow.tuxi</groupId>
  <artifactId>duplicatedjar</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <dependencies>
    <dependency>
      <groupId>org.apache.james</groupId>
      <artifactId>james-server</artifactId>
      <version>3.0-beta4</version>
      <type>pom</type>
    </dependency>
    <dependency>
      <groupId>org.apache.james</groupId>
      <artifactId>james-server-container-spring</artifactId>
      <version>3.0-beta4</version>
      <!-- DO NOT exclude all of them, only the conflicting ones -->
      <exclusions>
        <exclusion>
          <groupId>commons-io</groupId>
          <artifactId>commons-io</artifactId>
        </exclusion>
        <exclusion>
          <groupId>commons-pool</groupId>
          <artifactId>commons-pool</artifactId>
        </exclusion>
        <exclusion>
          <groupId>commons-logging</groupId>
          <artifactId>commons-logging</artifactId>
        </exclusion>
        <exclusion>
          <groupId>commons-collections</groupId>
          <artifactId>commons-collections</artifactId>
        </exclusion>
        <exclusion>
          <groupId>commons-lang</groupId>
          <artifactId>commons-lang</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>
</project>

OTHER TIPS

You should specify the jars corresponding to a sub project, that you want to exclude, in the dependency declaration of the main jar.

See the maven documentation for more details on how to define dependency exclusions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top