java - 多项目构建 : dependency to tests jar

标签 java gradle

我正在为一个大项目重组/重构构建过程。目前它包含十几个独立的模块,每个模块都使用独立的构建脚本构建。我想将它们全部集成到 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/

相关文章:

android - BuildConfig 未正确创建(Gradle Android)

maven - 通过代理的依赖处理程序(Maven,Gradle,Ivy)的URL

Gradle Exec : Why it is not running in configuration phase?

java - 桌面纵向设置?

java - 通用类型作为注释

java - 开关: duplicate case

gradle - 在gradle中引用另一个jar的库文件夹中的jar - 找不到类

gradle - java:软件包org.junit不存在

Java 套接字 Json

java - 如何让用户在 firebase 中拥有自己的聊天室和 map 标记?