多项目构建:依赖于测试jar

时间:2016-07-04 11:37:41

标签: java gradle

我正在重建/重构一个大型(ish)项目的构建过程。目前,它包含十几个独立的模块,每个模块都使用独立的构建脚本构建。我想将它们全部集成到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,而不是来自存储库。我将compile ...替换为compile project(':Module'),它运行正常。但是,我找不到将'tests'说明符传递给testCompile project...依赖项的方法。

有没有办法选择tests jar作为testCompile的依赖?

1 个答案:

答案 0 :(得分:1)

在制作项目中,您需要声明"测试" JAR作为传出神器。

configurations {
    testUtils
}

task testUtilsJar(type: Jar) {
    ...
}

artifacts {
    testUtils testUtilsJar
}

在消费项目中,你依赖它:

dependencies {
    testCompile project(path: ':Module', configuration: 'testUtils')
}
相关问题