[英]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
.有问题的类是
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
.我要使用的版本是由
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.但是,我们也使用 Jira rest 客户端库,它依赖于旧版本的 jersey (
com.sun.jersey:jersey-core
),其中包含捆绑在其 jar 中的 java.ws 包。
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.我无法删除
com.sun.jersey:jersey-core
因为它使用与新版本不同的包名,并且会导致在 Jira 客户端中出现 class def not found 异常。
As far as I can tell, my options at this point are:据我所知,此时我的选择是:
javax.ws
package from the old jersey client.javax.ws
包。 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.我想继续使用较新版本的球衣,所以 #2 将是我理想的解决方案,但我不确定它是否可能。 Does anyone know how to go about this?
有谁知道如何解决这个问题? If that's not possible, I'm open to other suggestions.
如果这是不可能的,我愿意接受其他建议。
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参考: 50.4.7 这里
I found out that com.sun.jersey:jersey-core:1.19 doesn't bundle the javax.ws.rs class files and instead lists them as a compile-time dependency.我发现 com.sun.jersey:jersey-core:1.19 没有捆绑 javax.ws.rs 类文件,而是将它们列为编译时依赖项。 Adding this snippet to my build.gradle fixed the issue.
将此代码段添加到我的 build.gradle 解决了该问题。
configurations.all {
resolutionStrategy {
// For a version that doesn't package javax.ws
force 'com.sun.jersey:jersey-core:1.19'
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.