【问题标题】:Why gradle clean task starts all other non-default tasks?为什么 gradle clean task 会启动所有其他非默认任务?
【发布时间】:2014-10-20 14:47:41
【问题描述】:

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

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

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

当我跑步时

./gradlew clean

gradle 运行setVersionsetIntegrationEnv 这两个任务,然后它为我在该项目中的所有模块(appcloud_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

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

【问题讨论】:

标签: gradle android-gradle-plugin


【解决方案1】:

您能否提供完整的build.gradle 脚本?我会更容易帮助你。您可能将 gradle build 阶段与 configuration 阶段混淆了——这是一个常见的话题。

一般规则是您希望在 build 阶段运行的代码应添加为 action

task someTask << {
   println 'runtime'
}

而你想在配置阶段运行的代码应该添加到任务正文中:

task someTask  {
   println 'configuration
}

或全部:

task someTask {
   println 'configuration'

   doLast {
      println 'runtime'
   }
}

可以在hereherehere 找到更多信息。

【讨论】:

  • 我建议始终使用doLast 而不是&lt;&lt;,因为使用&lt;&lt; 非常容易出错(容易忘记等)。
  • Marian Paździoch:这就是你要找的冷杉吗?
  • 是的,我标记为您提出的其中一个问题的重复项。
  • 如果是您要找的,请接受答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-09
  • 2014-06-04
  • 1970-01-01
  • 1970-01-01
  • 2019-01-13
相关资源
最近更新 更多