从Gradle依赖关系中排除软件包 [英] Exclude Package From Gradle Dependency

查看:133
本文介绍了从Gradle依赖关系中排除软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,即同一班级的多个版本显示在我的班级路径中。有问题的类是 javax.ws.rs.core.UriBuilder 。我想要使​​用的版本是由 javax.ws.rs:javax.ws.rs-api:2.0.1 引入的。但是,我们也使用Jira rest客户端库,它依赖于包含java的旧版泽西岛( com.sun.jersey:jersey-core )。 ws包捆绑在它的jar中。



以下是构建文件中的示例代码片段:

  dependencies {
compile'c​​om.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'
}

我不能删除 com.sun.jersey:jersey-core ,因为它使用新的不同包名版本,并会导致类def在Jira客户端没有发现异常。



据我所知,我的选项在这一点上是:


  1. 恢复使用Jersey 1.x并执行jsr311

  2. 不知何故,Gradle不包含 javax .ws 来自旧泽西客户端的软件包。

我想继续使用更新版本的球衣,所以#2将是我理想的解决方案,但我不确定是否甚至有可能。有谁知道如何去做这件事?如果这是不可能的,我可以接受其他建议。

我发现com.sun.jersey:jersey- core:1.19不捆绑javax.ws.rs类文件,而是将它们列为编译时间依赖项。

  configurations.all {
resolutionStrategy {
//对于不包装javax.ws的版本
force'com.sun.jersey:jersey-core:1.19'
}
}


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.

解决方案

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. Adding this snippet to my build.gradle fixed the issue.

configurations.all {
  resolutionStrategy {
    // For a version that doesn't package javax.ws
    force 'com.sun.jersey:jersey-core:1.19' 
  }
}

这篇关于从Gradle依赖关系中排除软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆