两个任务之间的Gradle冲突

时间:2015-04-20 16:55:39

标签: groovy gradle

我在gradle中写了几个任务,我有一个奇怪的错误。

task buildProduction() {
    description 'Build the production version of the app (creates the yaml file)'
    copyAndReplaceYaml("Production")
}

task buildStaging() {
    description 'Build the staging version of the app (creates the yaml file)'
    copyAndReplaceYaml("Staging")
}

当我运行buildStaging时,它运行正常,但是当我运行buildProduction时,它就像我正在运行buildStaging。

如果我切换文件buildProduction中方法的位置有效,而不是buildStaging

知道为什么会这样吗?

1 个答案:

答案 0 :(得分:5)

您正在执行副本作为任务配置的一部分,该任务始终执行,无论命令是什么,还是在执行任务之前。您需要将两个任务的代码更改为

task buildStaging {
    description 'Build the staging version of the app (creates the yaml file)'
}
buildStaging << {
    copyAndReplaceYaml("Staging")
}

task buildStaging {
    description 'Build the staging version of the app (creates the yaml file)'
    doLast {
        copyAndReplaceYaml("Staging")
    }
}