gpt4 book ai didi

gradle - 为什么我的 Gradle 任务总是在运行?

转载 作者:行者123 更新时间:2023-12-03 07:53:54 24 4
gpt4 key购买 nike

如果我运行 ./gradlew clean./gradlew tasks --all ,它总是在运行我的编译任务(我在 gradle 构建脚本中重写了它,如下所示)

task eclipse(overwrite: true) {
exec { commandLine = ["./play1.3.x/play", "eclipsify"] }
}

task compileJava(overwrite: true) {
exec { commandLine = ["./play1.3.x/play", "precompile"] }
}

task deleteDirs(type: Delete) {
delete 'precompiled', 'tmp'
}

//NOW, assemble needs to zip up directories precompiled, public, lib, and conf
clean.dependsOn('deleteDirs')

我不明白为什么 Eclipse 不是每次都运行,而且似乎在覆盖编译器不起作用的情况下工作得很好。

最佳答案

了解任务配置和任务执行的区别非常重要:

task eclipsify {
// Code that goes here is *configuring* the task, and will
// get evaluated on *every* build invocation, no matter
// which tasks Gradle eventually decides to execute.
// Don't do anything time-consuming here.
doLast {
// `doLast` adds a so-called *task action* to the task.
// The code inside the task action(s) defines the task's behavior.
// It will only get evaluated if and when Gradle decides to
// execute the task.
exec { commandLine = ["./play1.3.x/play", "eclipsify"] }
}
}

// Improving on the previous task declaration, let's now use a *task type*
// (see `type: Exec` below). Task types come with a predefined task action,
// so it's typically not necessary to add one yourself. Also, many task types
// predefine task inputs and outputs, which allows Gradle to check if the task
// is up-to-date. Another advantage of task types is that they allow for
// better tooling support (e.g. auto-completion of task properties).
task precompile(type: Exec) {
// Since this task already has a task action, we only
// need to configure it.
commandLine = ["./play1.3.x/play", "precompile"] }
}

如果您没有正确地进行配置与执行,您将看到诸如启动时间过长和任务看似在不应该执行的情况下执行等症状。

要了解哪些任务类型可用以及如何配置它们,请查看 Gradle Build Language Reference .此外,第三方插件和任务类型的列表也在不断增加。

PS:我更改了任务名称并删除了 overwrite: True (这只能用作最后的手段)以免分散我回答的主要信息。

关于gradle - 为什么我的 Gradle 任务总是在运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20737494/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com