1

I have a problem building an android maven project (eclipse m2e, android for maven).

The "install" goal resumes with:

[INFO] UNEXPECTED TOP-LEVEL EXCEPTION:
[INFO] java.lang.IllegalArgumentException: already added: Ljavax/persistence/Access;
[INFO]  at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)

I've added the following dependency to the project:

<dependency>
    <groupId>org.odata4j</groupId>
    <artifactId>odata4j-jersey</artifactId>
    <version>0.7.0</version>
</dependency>

This dependency adds also (among other things) javax.persistence-2.0.0.jar.

So I think the library is added twice? But how to solve this problem? When I remove the dependency the project can be built without errors.

Here is the output of the command: maven dependency:tree

[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ myapp ---
[INFO] org.subby.android:myapp:apk:0.0.1-SNAPSHOT
[INFO] +- com.google.android:android:jar:4.1.1.4:provided
[INFO] |  +- commons-logging:commons-logging:jar:1.1.1:provided
[INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.0.1:provided
[INFO] |  |  +- org.apache.httpcomponents:httpcore:jar:4.0.1:provided
[INFO] |  |  +- (commons-logging:commons-logging:jar:1.1.1:provided - omitted for  duplicate)
[INFO] |  |  \- commons-codec:commons-codec:jar:1.3:provided
[INFO] |  +- org.khronos:opengl-api:jar:gl1.1-android-2.1_r1:provided
[INFO] |  +- xerces:xmlParserAPIs:jar:2.6.2:provided
[INFO] |  +- xpp3:xpp3:jar:1.1.4c:provided
[INFO] |  \- org.json:json:jar:20080701:provided
[INFO] \- org.odata4j:odata4j-jersey:jar:0.7.0:compile
[INFO]    +- org.odata4j:odata4j-core:jar:0.7.0:compile
[INFO]    |  +- org.core4j:core4j:jar:0.5:compile
[INFO]    |  +- javax.ws.rs:jsr311-api:jar:1.1.1:compile
[INFO]    |  +- org.eclipse.persistence:javax.persistence:jar:2.0.0:compile
[INFO]    |  +- org.eclipse.persistence:eclipselink:jar:2.1.2:compile
[INFO]    |  \- joda-time:joda-time:jar:1.6:compile
[INFO]    +- com.sun.jersey:jersey-core:jar:1.1.5:compile
[INFO]    |  \- (javax.ws.rs:jsr311-api:jar:1.1.1:compile - omitted for duplicate)
[INFO]    +- com.sun.jersey:jersey-server:jar:1.1.5:compile
[INFO]    |  +- (com.sun.jersey:jersey-core:jar:1.1.5:compile - omitted for duplicate)
[INFO]    |  \- asm:asm:jar:3.1:compile
[INFO]    \- com.sun.jersey:jersey-client:jar:1.1.5:compile
[INFO]       \- (com.sun.jersey:jersey-core:jar:1.1.5:compile - omitted for duplicate)

Am I doing something wrong? I'm still very new on maven.

Thanks!

Subby
  • 1,997
  • 4
  • 22
  • 38

2 Answers2

2

This happens since you have a duplicate classes in your build. The ADT will throw s if your Eclipse classpath contains more than one class of the same name/package.

I would suggest running mvn dependency:tree where you would get the whole picture

[INFO] +- com.sun.jersey:jersey:jar:0.8-ea-SNAPSHOT:compil
[INFO] |  +- javax.ws.rs:jsr311-api:jar:0.8:compile
[INFO] |  \- asm:asm:jar:3.1:compile
[INFO] \- com.sun.jersey:jersey-client:jar:1.9.1:test
[INFO]    \- com.sun.jersey:jersey-core:jar:1.9.1:test

The duplicates are some dependencies being pulled transitively from odata4j-jersey. In order to fix them you would add some thing like this on the duplicates :

<project>
  ...
  <dependencies>
    <dependency>
      <groupId>sample.ProjectA</groupId>
      <artifactId>Project-A</artifactId>
      <version>1.0</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion>  <!-- declare the exclusion here -->
          <groupId>sample.ProjectB</groupId>
          <artifactId>Project-B</artifactId>
        </exclusion>
      </exclusions> 
    </dependency>
  </dependencies>
</project>
Mite Mitreski
  • 3,596
  • 3
  • 29
  • 39
  • Hi and thanks for your answer. In the dependency-tree I see the javax persistence only once. So I don't know where the second occurence of this class comes from. I'm not really sure what to put into the exclusions. – Subby Jan 24 '13 at 15:16
  • can you please add the log as comment `mvn dependency:tree -Dverbose` – Mite Mitreski Jan 24 '13 at 17:47
  • Sure, I added the dependency output. – Subby Jan 24 '13 at 21:02
1

I got the solution:

It seems that the two dependencies of odata4j:

eclipselink-2.1.2
javax.persistence

have some classes in common.

So the problem is solved when either the one or the other dependency is excluded.

Seems like this is really just an android/adt issue. Normally you do not need to exclude dependencies of a single artifact, do you?

The dependency now looks like this:

<dependency>
    <groupId>org.odata4j</groupId>
    <artifactId>odata4j-core</artifactId>
    <version>0.7.0</version>
    <exclusions>
        <exclusion>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>javax.persistence</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Big thanks to Mite for the helpful hint.

Regards, Alex

Subby
  • 1,997
  • 4
  • 22
  • 38