我的构建中有以下简单任务:
task generateFile << {
def file = new File("$buildDir/setclasspath.sh")
file.text = "sample"
outputs.file(file)
}
task createDistro(type: Zip, dependsOn: ['copyDependencies','packageEnvironments','jar', 'generateFile']) <<{
from generateClasspathScript {
fileMode = 0755
into 'bin'
}
}
当我运行gradle clean build
时,我看到以下输出:
Cannot call TaskOutputs.file(Object) on task ':generateFile' after task has started execution. Check the configuration of task ':generateFile' as you may have misused '<<' at task declaration
如何将任务文件创建输出声明为zip任务的输入,同时确保它们在执行阶段发生?
如果我放弃&lt;&lt;然后,clean任务会在ZIP可以使用它之前擦除生成的文件。如果我保留它们,我会收到上述错误。
答案 0 :(得分:2)
与评论中的建议相反。您正尝试在执行阶段设置输出。做你可能想要做的事的正确方法是例如:
task generateFile {
def file = new File("$buildDir/setclasspath.sh")
outputs.file(file)
doLast {
file.text = "sample"
}
}