如何覆盖一个依赖项的配置级别 "transitive = false"

How to override configuration level "transitive = false" for one dependency

我继承了一些代码,想在项目中添加黄瓜,最好尽量少改动。但是 gradle 文件有一个配置级别设置来阻止传递依赖项被引入,这导致 cucumber-java 无法引入 cucumber-core 并因此失败。

所以这里是build.gradle的相关部分:

configurations.all {
  transitive = false
}

depdendencies {
  compile(group: .... lots of these

  testCompile(group: 'io.cucumber', name: 'cucumber-java8', version: '4.8.0', transitive: true)
  testCompile(group: 'io.cucumber', name: 'cucumber-testng', version: '4.8.0', transitive: true)
}

我希望 transitive: true 会覆盖配置级别,但它不起作用。

我也试过添加:

configurations {
  all*.exclude group: 'io.cucumber', module: 'cucumber-java8'
}

但它根本不会引入这种依赖性

我不想手动引入 cucumber 的所有依赖项,我也不想删除此配置级别 transitive = false。有可能做我正在尝试的事情吗?我可以只为 compile 依赖项设置配置吗?或者我是否必须删除配置级别设置并将 transitive: false 添加到每个编译依赖项?

谢谢你的帮助

我想你正在寻找这样的东西:

configurations {
 compile {
    transitive false
  }
 testCompile {
    transitive true
  }
}