Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

This dependency gives me two versions of one jar. How do I fix this?

I'm using Gradle for my project. One of the dependencies I have specified in my build.gradle is
compile 'org.glassfish.jersey.media:jersey-media-moxy:2.0'

This works fine on a normal Java application, however when I try to build it on Android I get:

When looking at which libraries are referenced, it's clear that there's both javax.inject-2.3.0-b05.jar and javax.inject-1.jar, which I found are added by the dependency above. I'm guessing that this 'duplicate' jar is what causes the build error.

How do I go around this? Why does the dependency include two of the same jar? Is there a way to either make the Android version build with these two jars or to remove one of these jars?

like image 869
user717572 Avatar asked Jul 06 '14 18:07

user717572


2 Answers

It appears that you have a dependency tree akin

project
|--- org.glassfish.jersey.media:jersey-media-moxy:2.0
| \--- *:javax.inject:1
\--- *:javax.inject:2.3.0-b05

Where * is the group, which I suspect may be different from those two.

Try getting an idea of how your dependencies are being grabbed by using the dependency task

gradle dependency

Should you need to exclude a dependency enter it in the tag, similar to the below example

compile('org.hibernate:hibernate:3.1') {
  //excluding a particular transitive dependency:
  exclude module: 'cglib' //by artifact name
  exclude group: 'org.jmock' //by group
  exclude group: 'org.unwanted', module: 'iAmBuggy' //by both name and group
}
like image 145
Niels Bech Nielsen Avatar answered Oct 06 '22 15:10

Niels Bech Nielsen


Normally gradle will only include 1 jar per dependency. If different version found for the same depedencies, the newer version will be used.

However, in your case, these 2 jars are dependencies with different group names:

'javax.inject:javax.inject:1'
'org.glassfish.hk2.external:javax.inject:2.3.0-b05'

That's why gradle included both as they are treated as different dependencies.

'javax.inject:javax.inject:1' is very old, I think you should exclude it like what Niels Bech Nielsen said.

To find out where is this dependency come from , you can use command:

gradle -q dependencyInsight --dependency inject
like image 22
Bill Lin Avatar answered Oct 06 '22 14:10

Bill Lin