gradle 多项目构建覆盖子项中的依赖项

gradle multi project build override dependencies in child

在 gradle 多项目构建中:

root << applies: dependency{ 'org:module:version1' }
|- foo (version1) is ok here
|- bar (version1) not ok here, I need to use version 2

有没有办法实现这种行为?

您可以使用的替代方法是 strictly 关键字。在你的 bar 模块中你可以这样写:

dependencies {
    //Other dependencies
    compile("org:module") {
        version {
            strictly version2
        }
        because("Only version2 works in this module")
    }
}

此外,如果您检查 bar 模块依赖关系图:

./gradlew -q dependencies

你会得到这样的输出:

compileClasspath - Compile classpath for source set 'main'.
+--- project :
|    +--- org.sample:dependency:1.0
|    +--- org.sample:other-dependency:1.0
|    \--- org:module:{strictly version2} -> version2