Gradle:通过版本分类器覆盖传递依赖 [英] Gradle: Override transitive dependency by version classifier

查看:460
本文介绍了Gradle:通过版本分类器覆盖传递依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中声明的一个依赖关系对'com.google.guava:guava:15.0'具有传递依赖性。但是,由于在'com.google.guava:guava:15.0:cdi1.0'中修复了CDI问题,因此部署在WAS / Weblogic上的应用程序不起作用。 。 (相同的版本,但有分类器)我需要告诉gradle在构建和打包期间使用这个jar。我试图找出如何使用特定于jar的版本分类器来对这种传递性依赖关系进行ovrride。



尝试了以下方法:


  1. 显式添加了依赖项: compile'c​​om.google.guava:guava:15.0:cdi1.0'。但是两个罐子都包含在WAR中。


  2. $ b p> configurations.all {
    resolutionStrategy {
    force'com.google.guava:guava:15.0:cdi1.0'
    }
    }

    即使这样也行不通。

      configurations.all {
    resolutionStrategy.eachDependency {DependencyResolveDetails详情 - >
    if(details.requested.group +:+ details.requested.name =='com.google.guava:guava'){
    details.useVersion15.0:cdi1.0
    //details.useTargetcom.google.guava:guava:15.0:cdi1.0
    }
    }
    }

    即使这样也行不通。 如何解决这个问题需要您的建议。

    解决方案

    当涉及到resolutionStrategies时,目前的分类器还没有考虑到。当你声明你的依赖关系并明确添加guava cdi1.0版本时,你的解决方法可能会排除传递guava lib:

      dependencies { 
    compile(org.acme:someDependency:1.0){
    exclude group:'com.google.guava',module:'guava'
    }
    compilecom。 google.guava:guava:15.0:cdi1.0


    One of the dependencies declared in my project has a transitive dependency on 'com.google.guava:guava:15.0'. But my application deployed on WAS/Weblogic doesn't work due to a CDI issue which has been fixed in 'com.google.guava:guava:15.0:cdi1.0'. (same version, but with classifier) I need to tell gradle to use this jar during build and packaging. I am trying to figure on how we can ovrride this transitive dependency with a jar specific version classifier.

    Tried the following approches:

    1. Added the dependency explicitly: compile 'com.google.guava:guava:15.0:cdi1.0'. But both jars got included in the resultant WAR.
    2. Added the dependency explicitly and defined a resolution strategy:

      configurations.all {
          resolutionStrategy {
              force 'com.google.guava:guava:15.0:cdi1.0'
          }
      }
      

      Even this didn't work.

    3. Defined a resolution strategy to check and change the version.

      configurations.all {
           resolutionStrategy.eachDependency { DependencyResolveDetails details ->
               if (details.requested.group + ":" + details.requested.name == 'com.google.guava:guava') {
                  details.useVersion "15.0:cdi1.0"
                  //details.useTarget "com.google.guava:guava:15.0:cdi1.0"
              }
          }
      }
      

      Even this didn't work.

    Need your suggestions on how this issue can be tackled.

    解决方案

    currently classifiers are not yet taken into account when it comes to resolutionStrategies. A workaround for you might excluding the transitive guava lib when declaring your dependencies and adding the guava cdi1.0 version explicitly:

    dependencies {
        compile ("org.acme:someDependency:1.0"){
            exclude group: 'com.google.guava', module: 'guava'
        }       
        compile "com.google.guava:guava:15.0:cdi1.0"
    }
    

    这篇关于Gradle:通过版本分类器覆盖传递依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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