Gradle在执行ZIP任务之前清除我的文件 [英] Gradle clean erasing my file prior to ZIP task execution

查看:405
本文介绍了Gradle在执行ZIP任务之前清除我的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的构建中,我有以下简单任务:

  task generateFile<< {
def file = new File($ buildDir / setclasspath.sh)
file.text =sample

outputs.file(file)
}
$ b任务createDistro(类型:Zip,dependsOn:['copyDependencies','packageEnvironments','jar','generateFile'])<<< {$ b $ from generateClasspathScript {
fileMode = 0755
到'bin'
}
}

当我运行 gradle clean build 时,我看到以下输出:

 任务开始执行后,无法在任务':generateFile'上调用TaskOutputs.file(Object)。检查任务':generateFile'的配置,因为您可能在任务声明



时误用了'< p>我如何将任务文件创建输出声明为zip任务的输入,同时确保它们在执行阶段发生?



如果我忽略< p> <那么干净的任务在ZIP可以使用之前擦除生成的文件。如果我保留它们,我会得到上述错误。 解决方案

这与评论中提出的内容正好相反。您正尝试将输出设置为执行阶段。例如:

  task generateFile {
def file =新文件($ buildDir / setclasspath.sh)
outputs.file(文件)
doLast {
file.text =sample
}
}


I have the following simple task in my build:

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'
 }
}

When I run gradle clean build I see the following output:

   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

How do I declare the task file creation outputs as an input to the zip task while also ensuring they happen in the execution phase?

If I leave off the << then the clean task wipes the generated file before the ZIP can use it. If I keep them, I get the above error.

解决方案

It's the opposite as what is being suggested in the comments. You are trying to set the outputs in execution phase. The correct way to do what you are probably trying to do is for example:

task generateFile {
    def file = new File("$buildDir/setclasspath.sh")
    outputs.file(file)
    doLast {
        file.text = "sample"
    }
}

这篇关于Gradle在执行ZIP任务之前清除我的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆