我有一个多模块gradle项目,看起来像这样:
Parent |--server |--application (android module) +--common
服务器测试依赖于通用模块测试.为此,我补充道
testCompile files(project(':common').sourceSets.test.output.classesDi compileTestJava.dependsOn tasks.getByPath(':common:testClasses')
它运作得很好.不幸的是,当我试图对同样依赖于公共模块测试的应用程序模块做同样的事情时,它也行不通.它失败了:
Build file 'application\build.gradle' line: 103 A problem occurred evaluating project ':application'. Could not find property 'sourceSets' on project ':common'
谷歌搜索后我也试过了
project.evaluationDependsOn(':common') testCompile files(project(':common').sourceSets.test.output.classesDir)
但失败了另一个例外:
Project application: Only Jar-type local dependencies are supported. Cannot handle: common\build\classes\test
有想法该怎么解决这个吗?
在本文中,有几种方法可以解决导入测试类的问题.https://softnoise.wordpress.com/2014/09/07/gradle-sub-project-test-dependencies-in-multi-project-builds/我使用的是:
共享模块中的代码:
task jarTest (type: Jar) { from sourceSets.test.output classifier = 'test' } configurations { testOutput } artifacts { testOutput jarTest }
模块中的代码取决于共享模块:
dependencies{
testCompile project(path: ':common', configuration: 'testOutput')
}
它似乎也有一个插件!https://plugins.gradle.org/plugin/com.github.hauner.jarTest/1.0
遵循sakis的方法,这应该是您需要从Android平台中的另一个项目中获得测试的配置(已完成调试变体)。共享模块:
task jarTests(type: Jar, dependsOn: "assembleDebugUnitTest") { classifier = 'tests' from "$buildDir/intermediates/classes/test/debug" } configurations { unitTestArtifact } artifacts { unitTestArtifact jarTests }
您的模块:
dependencies { testCompile project(path: ":libName", configuration: "unitTestArtifact") }