48

Many of my jars have conflicting transitive dependencies (multiple spring versions). I would like to avoid inherited version conflicts by managing all of my dependencies explicitly, is it possible to disable all transitive dependencies in Gradle?

I know I can add transitive = false to each of my dependencies, but I am hoping there is a simpler way.

compile(group: 'org.springframework', name: 'spring', version: '2.5.2') {
    transitive = false
}
4

3 回答 3

56

我最终使用:

configurations.all {
    transitive = false
}
于 2013-07-23T21:13:19.520 回答
9

如果您只想为所有配置提供一个配置块,您可以使用扩展点运算符来表达这一点。

configurations {
    // other configurations e.g. - compile.exclude module: 'commons-logging'
    all*.transitive = false
}
于 2014-11-30T20:09:54.360 回答
5

就我而言,我有一个项目(gradle 模块)依赖。我使用以下内容来排除 Gradle 3 中的传递依赖项:

implementation(project(':<module_name>')) {
    transitive = false
}

或者在 Kotlin 脚本中:

implementation(project(':<module_name>')) {
    isTransitive = false
}
于 2018-05-02T21:58:13.880 回答