摇篮的任务不应该自动执行 [英] Gradle task should not execute automatically
问题描述
我在定义的gradle任务:
I'm defining a task in gradle:
task releaseCandidate(type: Exec) {
commandLine 'git', 'checkout', 'develop'
// Increment version code in Manifest
String manifest = new File('AndroidManifest.xml').getText('UTF-8')
Pattern pattern = Pattern.compile('android:versionCode="([0-9]+)"')
Matcher matcher = pattern.matcher(manifest)
matcher.find()
int newVersionCode = Integer.parseInt(matcher.group(1)) + 1
manifest = manifest.replaceAll(
"android:versionCode=\"([0-9]+)\"", "android:versionCode=\"$newVersionCode\""
)
new File('AndroidManifest.xml').write(manifest, 'UTF-8')
commandLine 'git', 'diff'
}
,我想执行只有当我明确地调用它作为 gradle这个releaseCandidate
。 然而,当我运行的任何其他任务,如 gradle这个assembleDebug
,它也运行任务releaseCandidate。我不希望这样的行为发生。有根据releaseCandidate反之亦然没有任务。
Which I want to execute only when I explicitly call it as gradle releaseCandidate
. However, when I run any other task, such as gradle assembleDebug
, it also runs task releaseCandidate. I don't want that behaviour to happen. There is no task depending on releaseCandidate or vice-versa.
我的项目是一个Android应用程序,所以我使用机器人
插件的gradle
My project is an Android app, so I am using android
gradle plugin.
推荐答案
一个常犯的错误。一个动作添加到任务,否则code将在配置阶段运行。用行动示例任务:
A common pitfall. Add an action to the task otherwise code will run at configuration phase. Sample task with action:
task sample << {
}
当我看到你宁愿需要编写比使用自定义任务 Exec的
键入。我想这是无效的定义命令行
两次。
As I see You'd rather need to write a custom task than using Exec
type. I suppose it's not valid to define commandLine
twice.
这篇关于摇篮的任务不应该自动执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!