我正在尝试使用 3 个模块(A、B、C)编写一个 gradle 构建。 A依赖B,B依赖C(A->B->C)。所有模块都位于同一个父目录中。
所有关闭的模块都可以存在于工作区中,这就是为什么我的设置 乙 .gradle 看起来像这样:
if(new File("../C").exists()){
include 'C'
project(":C").projectDir = file("../C")
}
在依赖项中我做同样的检查: dependencies {
if(new File("../C").exists()) {
compile project(':C')
}else {
compile "com.mycompany.C:0.0.14"
}
此设置完美运行,但不适用于顶级模块 A。如果我将 B 添加到 A,以与上面相同的方式,我在构建项目 A 时遇到错误:Build file 'C:\projects\A\build.gradle' line: 44 A problem occurred evaluating project ':B'. Project with path ':C' could not be found in project ':B'.
解决这个问题的唯一方法是将模块 C 添加到项目 A 的 settings.gradle 中。
有没有其他方法可以解决错误?
先感谢您
最佳答案
解决方案是复合构建 (https://docs.gradle.org/current/userguide/composite_builds.html)
settings.gradle
includeBuild('../B') {
dependencySubstitution {
substitute module('com.mycompany:B') with project(':')
}
}
settings.gradle includeBuild('../C') {
dependencySubstitution {
substitute module('com.mycompany:C') with project(':')
}
}
关于java - Gradle 子项目构建配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64464037/