我正在为一个大项目重组/重构构建过程。目前它包含十几个独立的模块,每个模块都使用独立的构建脚本构建。我想将它们全部集成到 Gradle 中的单个多项目构建中。
将所有源集成到一个树中并修复 build.gradle
后,我遇到了以下问题。许多模块的依赖项包含以下内容:
dependencies {
compile group: 'com.company', name: 'Module', version: '1.2.3'
// ...
testCompile group: 'com.company', name: 'Module', version: '1.2.3', classifier: 'tests'
}
我希望构建使用子项目中的 jar,而不是存储库中的 jar。我用 compile project(':Module')
替换了 compile ...
,它工作得很好。但是,我找不到将“tests”说明符传递给 testCompile 项目...
依赖项的方法。
有没有办法将 tests
jar 作为 testCompile
的依赖项?
最佳答案
在生产项目中,您需要将“测试”JAR 声明为传出工件。
configurations {
testUtils
}
task testUtilsJar(type: Jar) {
...
}
artifacts {
testUtils testUtilsJar
}
在使用项目中,您这样依赖它:
dependencies {
testCompile project(path: ':Module', configuration: 'testUtils')
}
关于java - 多项目构建 : dependency to tests jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38183795/