6

我有以下项目结构:

  • 应用
    • 构建.gradle
  • 构建.gradle
  • 设置.gradle

应用程序/build.gradle:

apply plugin: 'java'

设置.gradle:

include ':application'

构建.gradle:

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

所以我想在任务“自定义”中执行任务“构建”。但是当我运行“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

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

4

1 回答 1

6

你不能。任务执行是声明式的,而不是命令式的。任务相互依赖,它们不相互执行。(另外,由于您没有在根构建脚本中应用 Java(基础)插件,因此根项目没有build任务。)

于 2013-05-21T08:47:38.183 回答