首页 文章

如何在Gradle中执行任务?

提问于
浏览
4

我有以下项目结构:

  • 申请

  • build.gradle

  • build.gradle

  • settings.gradle

应用/的build.gradle:

apply plugin: 'java'

settings.gradle:

include ':application'

的build.gradle:

task custom << {
  project.tasks.getByName("build").execute()
}

所以我想在任务“custom”中执行任务“build” . 但是当我运行“gradle custom”时,结果是:

:custom FAILED

FAILURE: Build failed with an exception.

* Where:
Build file '/tmp/test/build.gradle' line: 3

* What went wrong:
Execution failed for task ':custom'.
> Task with name 'build' not found in root project 'test'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 1.183 secs

如何在“自定义”任务中执行“构建”任务?

1 回答

  • 6

    你不能 . 任务执行是声明性的,而不是命令式的 . 任务相互依赖,不会相互执行 . (另外,因为你没有't apply the Java (base) plugin in the root build script, the root project doesn'任务 . )

相关问题