Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
577 views
in Technique[技术] by (71.8m points)

java - Exclude Package From Gradle Dependency

I'm experiencing an issue where multiple versions of the same class are showing up in my classpath. The class in question is javax.ws.rs.core.UriBuilder. The version I want to use is brought in by javax.ws.rs:javax.ws.rs-api:2.0.1. However, we also use the Jira rest client library which has a dependency on the older version of jersey (com.sun.jersey:jersey-core) which has included the java.ws packages bundled in it's jar.

Here is an example snippet from the build file:

dependencies {
  compile 'com.atlassian.jira:jira-rest-java-client-core:2.0.0-m31'
  compile 'javax.ws.rs:javax.ws.rs-api:2.0.1'
  compile 'org.glassfish.jersey.core:jersey-client:2.17'
}

I can't remove com.sun.jersey:jersey-core as it uses different package name from the new version and would cause class def not found exceptions in the Jira client.

As far as I can tell, my options at this point are:

  1. Revert to using Jersey 1.x and it's implementation of jsr311
  2. Somehow have gradle exclude the javax.ws package from the old jersey client.

I'd like to keep using the newer version of jersey so #2 would be my ideal solution but I'm not sure if it's even possible. Does anyone know how to go about this? If that's not possible, I'm open to other suggestions.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can exclude an transitive dependency module like this:

   compile ('org.glassfish.jersey.core:jersey-client:2.17') {
      exclude group: 'javax.ws.rs'
      exclude module: 'javax.ws.rs-api'
   }

ref: 50.4.7 here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...