使用 gradle 的多项目测试依赖项
我有一个多项目配置,我想使用 gradle.
I have a multi-project configuration and I want to use gradle.
我的项目是这样的:
项目A
- ->
src/main/java - ->
src/test/java
项目B
- ->
src/main/java(取决于Project A上的src/main/java) - ->
src/test/java(取决于Project A上的src/test/java)
- ->
src/main/java(depends onsrc/main/javaon Project A) - ->
src/test/java(depends onsrc/test/javaon Project A)
我的Project B build.gradle文件是这样的:
apply plugin: 'java'
dependencies {
compile project(':ProjectA')
}
compileJava 任务运行良好,但 compileTestJava 无法从 Project A 编译测试文件.
The task compileJava work great but the compileTestJava does not compile the test file from Project A.
推荐答案
已弃用 - 对于 Gradle 5.6 及更高版本,请使用 this answer.
在Project B中,只需要添加一个testCompile依赖:
Deprecated - For Gradle 5.6 and above use this answer.
In Project B, you just need to add a testCompile dependency:
dependencies {
...
testCompile project(':A').sourceSets.test.output
}
使用 Gradle 1.7 测试.
Tested with Gradle 1.7.
相关文章