Java – exclude packages from gradle dependencies
I encountered a problem that multiple versions of the same class appeared in my classpath The problematic class is javax ws. rs.core. UriBuilder. The version I want to use is javax ws. rs:javax. ws. rs-api:2.0. 1 introduced However, we also use the JIRA rest client library, which relies on the old version of Jersey (COM. Sun. Jersey: Jersey core), which contains Java. Net bundled in its jar Ws package
The following is a sample code 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 delete com sun. Jersey: Jersey core, because it uses different package names of the new version, and will cause class def found exception in JIRA client
As far as I know, my current choice is:
>Return to Jersey 1 X and execute jsr311 > to some extent, gradle excluded javax from the old Jersey client Ws package
I want to continue to use the updated Jersey, so #2 it will be my ideal solution, but I'm not sure if it's possible Who knows how to do it? If that is impossible, I will accept other suggestions
Solution
You can exclude such delivery dependent modules:
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