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

跟風遠走 提交于 2019-12-07 02:38:26

问题


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?


回答1:


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
}



回答2:


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


来源:https://stackoverflow.com/questions/24598961/this-dependency-gives-me-two-versions-of-one-jar-how-do-i-fix-this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!