我有一个多项目构建。构建中的一些项目产生测试结果。一个项目生成一个安装程序,我希望该项目的工件包含来自所有其他项目的测试结果。我尝试这样做(在生成安装程序的项目中):
// 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解决这种性质的问题。我想我在概念上遗漏了一些东西。
答案 0 :(得分:1)
在这种情况下,你应该能够通过添加<<
来使其成为一种行动,如
task gatherDependentTestResults( type: Zip, dependsOn: test ) << {
// your task code here
}