0
我有一個多項目構建。構建中的一些項目會生成測試結果。一個項目產生一個安裝程序,我希望該項目的工件包含所有其他項目的測試結果。我試圖做這樣的(在產生一個安裝程序的項目):在Gradle構建生命週期後期配置任務
// 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的這種性質的問題。我想我在概念上錯過了一些東西。
似乎不是爲我工作 - 任務總是被認爲是上TO-日期。 該任務必須是Zip或類似的,因爲我打算在工件腳本塊中使用它,但是如果我將代碼放入像這樣的操作中,則Zip任務不會配置(至少我假設這就是發生了什麼)。 –
添加zip任務依賴的另一個任務,並使用該任務來執行配置(zip任務) – Matt