【问题标题】:Appending dependsOn for a modules build task when the build task already exists当构建任务已经存在时,为模块构建任务附加dependsOn
【发布时间】:2020-12-01 16:58:30
【问题描述】:

我有一个 Gradle 多项目。项目中的所有模块都引入了一个自定义插件,该插件定义了build 任务,即所有常见的构建步骤。它们都是 Java 项目/模块。

在其中一个名为 alt 的项目中,我想说明它的构建应该特别依赖于另外两个任务,即 "app-bundle", "intern"

但是当我为alt 设置以下内容时,我收到以下错误。

alt 的构建附加这个额外的dependsOn 逻辑的语法是什么?

build.gradle:

val rootBuild = task("build") {
    dependsOn("app-bundle", "intern")
}

错误:

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/rob/git/root-project/alt/build.gradle.kts' line: 22

* What went wrong:
Cannot add task 'build' as a task with that name already exists.

【问题讨论】:

    标签: gradle build build.gradle


    【解决方案1】:

    希望下面的例子有所帮助

    task("custom1") {
        println("from custom task")
    }
    
    tasks["build"].dependsOn("custom1")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多