Gradle 跨模块依赖测试代码

gradle中,模块A依赖core模块的测试代码

测试代码(test文件夹下的代码),是不跟随打包发布的,而且默认不随project依赖传递到其他的模块,需要用.sourceSets.test.output指明

简单配置,如下:

1
2
3
4
5
6
// A's build.gradle
dependencies {
compile project(':core')
//...
testCompile project(':core').sourceSets.test.output
}

或者,configuration of testOutput

以上只是简单的配置,也可以配置一个testOutput configuration,具体如下:

1
2
3
4
5
6
7
// core's build.gradle
configurations {
testOutput
}
dependencies {
testOutput sourceSets.test.output
}

然后

1
2
3
4
5
// A's build.gradle
dependencies {
//...
testCompile project(path: ':core', configuration: 'testOutput')
}

参考链接