我有一个多项目构建。构建中的一些项目会产生测试结果。一个项目生成一个安装程序,我希望该项目的工件包含所有其他项目的测试结果。我试图这样做(在生成安装程序的项目中):
// Empty test task, so that we can make the gathering of test results here depend on the tests' having
// been run in other projects in the build
task test << {
}
def dependentTestResultsDir = new File( buildDir, 'dependentTestResults' )
task gatherDependentTestResults( type: Zip, dependsOn: test ) {
project.parent.subprojects.each { subproject ->
// Find projects in this build which have a testResults configuration
if( subproject.configurations.find { it.name == 'testResults' } ) {
// Extract the test results (which are in a zip file) into a directory
def tmpDir = new File( dependentTestResultsDir, subproject.name )
subproject.copy {
from zipTree( subproject.configurations['testResults'].artifacts.files.singleFile )
into tmpDir
}
}
}
// Define the output of this task as the contents of that tree
from dependentTestResultsDir
}
问题是,在配置此任务时,其他项目中的测试任务尚未运行,因此它们的工件不存在,并且我在构建过程中收到如下消息:
The specified zip file ZIP 'C:\[path to project]\build\distributions\[artifact].zip' does not exist and will be silently ignored. This behaviour has been deprecated and is scheduled to be removed in Gradle 2.0
所以我需要做一些事情,将我的任务配置延迟到实际生成测试工件为止。实现这一目标的惯用方法是什么?
我似乎需要经常解决有关 Gradle 的此类问题。我想我在概念上遗漏了一些东西。