且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我可以从.gradle文件中的groovy方法调用gradle任务吗?

更新时间:2023-12-05 14:57:10

First of all, you should never call a task from another task - bad things will happen if you do. Instead, you should declare a relationship between the two tasks (dependsOn, mustRunAfter, finalizedBy).

In some cases (fewer than people tend to believe), chaining tasks may not be flexible enough; hence, for some tasks (e.g. Copy) an equivalent method (e.g. project.copy) is provided. However, these methods should be used with care. In many cases, tasks are the better choice, as they are the basic building blocks of Gradle and offer many advantages (e.g. automatic up-to-date checks).

Occasionally it also makes sense to use a GradleBuild task, which allows to execute one build as part of another.