为什么 gradle clean 任务会启动所有其他非默认任务?

2024-03-10

我已经设置并运行了 gradle。我的build.gradle里面定义了 2 个任务:

task setVersion() {
    println('setVersion')
    //...
}

task setIntegrationEnv() {
    println('setIntegrationEnv')
    //...
}

当我跑步时

./gradlew clean

gradle 运行这两个任务setVersion and setIntegrationEnv然后它对我的所有模块都运行干净(app, cloud_module)在该项目中,输出:

Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
setVersion
setIntegrationEnv
:cloud_module:clean
:app:clean

BUILD SUCCESSFUL

Total time: 14.18 secs

为什么会发生这种情况,这种行为是在哪里定义的?


您能否提供完整的build.gradle脚本?我会更容易帮助你。你可能误会了 gradlebuild相与配置阶段 - 这是这里的一个常见话题。

一般规则是您希望运行的代码build应添加相作为action:

task someTask << {
   println 'runtime'
}

而您想要运行的代码配置应在任务主体中添加阶段:

task someTask  {
   println 'configuration
}

或全部一起:

task someTask {
   println 'configuration'

   doLast {
      println 'runtime'
   }
}

可以找到更多信息here https://stackoverflow.com/questions/24818951/what-is-the-purpose-of-in-groovy/24819059#24819059, here https://stackoverflow.com/questions/26085379/whats-the-operator/26085415#26085415 and here https://stackoverflow.com/questions/23546286/gradle-task-should-not-execute-automatically/23546350#23546350.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么 gradle clean 任务会启动所有其他非默认任务? 的相关文章

随机推荐