我有一个多项目构建。构建中的某些项目会产生测试结果。一个项目产生一个安装程序,我希望该项目的 Artifact 包括所有其他项目的测试结果。我试图这样做(在产生安装程序的项目中):
// 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
}
问题在于,在配置此任务时,其他项目中的测试任务尚未运行,因此它们的 Artifact 不存在,并且我在构建过程中收到如下消息:
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
因此,我需要做的事情将延迟我的任务的配置,直到实际生成测试 Artifact 为止。实现此目的的惯用方式是什么?
我似乎需要就Gradle经常回答这种性质的问题。我认为我在概念上缺少一些东西。
最佳答案
在这种情况下,您应该可以通过添加<<
使其成为一个 Action ,如下所示:
task gatherDependentTestResults( type: Zip, dependsOn: test ) << {
// your task code here
}
关于gradle - 在Gradle构建生命周期的后期配置任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17742540/