Gradle, How To Disable All Transitive Dependencies

2020-02-09 05:42发布

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
}

3条回答
SAY GOODBYE
2楼-- · 2020-02-09 06:14

If you want to have just one configuration block for all configurations you can use spread-dot operator to express this.

configurations {
    // other configurations e.g. - compile.exclude module: 'commons-logging'
    all*.transitive = false
}
查看更多
ら.Afraid
3楼-- · 2020-02-09 06:30

I ended up using:

configurations.all {
    transitive = false
}
查看更多
可以哭但决不认输i
4楼-- · 2020-02-09 06:33

In my case, I had a project (gradle module) depedency. I used the following to exclude the transitive dependencies in Gradle 3:

implementation(project(':<module_name>')) {
    transitive = false
}
查看更多
登录 后发表回答