如何忽略Gradle中所有依赖项的特定传递依赖项

Ami*_*deh 17 dependency-management gradle transitive-dependency

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

例如,许多库(例如Spring和...)依赖于commons-logging,我想commons-loggingSLF4J(和它的jcl-over-slf4j桥)替换.

我的gradle脚本中是否有任何提及它的方式,而不是依赖于每个依赖的依赖commons-logging

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

Ori*_*Dar 20

configurations {
    compile.exclude group: 'commons-logging'
}
Run Code Online (Sandbox Code Playgroud)

  • 或者:`configurations.all {exclude group:'commons-logging'}`. (9认同)

use*_*253 17

来到这里有同样的问题,但最终使用以下来做一个实际的替换.为了完整性而发布它.

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

  • 在处理此类任务时,感谢您的回答和Gradle的优雅. (2认同)