【问题标题】:How to ignore a specific transitive dependency from all dependencies in Gradle如何从 Gradle 中的所有依赖项中忽略特定的传递依赖项
【发布时间】:2013-11-28 05:37:39
【问题描述】:

如何在 Gradle 中忽略特定的传递依赖?

例如,许多库(例如 Spring 和 ...)依赖于 commons-logging,我想将 commons-logging 替换为 SLF4J(及其 jcl-over-slf4j 桥)。

是否可以在我的 gradle 脚本中提及一次,而不是针对每个依赖于 commons-logging 的依赖项?

我正在考虑一个脚本,迭代所有依赖项并在所有依赖项上添加一些exclude,有没有更好的解决方案?那个剧本怎么样?

【问题讨论】:

标签: gradle dependency-management transitive-dependency


【解决方案1】:

带着同样的问题来到这里,但最终使用以下内容进行实际替换。为了完整起见发布它。

configurations.all {
    resolutionStrategy.eachDependency {
        if(it.requested.name == 'commons-logging') {
            it.useTarget 'org.slf4j:jcl-over-slf4j:1.7.7'
        }
    }
}

【讨论】:

  • 感谢您的回答和 Gradle 在处理此类任务时的优雅。
  • 我想补充一点,与此同时,一个新的 Gradle 版本已经发布,并且它具有模块替换功能。还没有尝试过,但看起来他们可能会做同样的事情。
  • 为这个问题而来,找到了更好的答案。 ;)
【解决方案2】:
configurations {
    compile.exclude group: 'commons-logging'
}

【讨论】:

  • 或:configurations.all { exclude group: 'commons-logging' }
  • 有没有办法排除特定版本的组?
猜你喜欢
  • 2013-04-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-02
  • 1970-01-01
  • 2010-10-07
  • 1970-01-01
相关资源
最近更新 更多