6

次のプロジェクト構造があります。

  • 応用
    • build.gradle
  • build.gradle
  • settings.gradle

アプリケーション/build.gradle:

apply plugin: 'java'

settings.gradle:

include ':application'

build.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

それはいけません。タスクの実行は宣言的であり、命令的ではありません。タスクは互いに依存しており、互いに実行することはありません。build(また、ルート ビルド スクリプトで Java (ベース) プラグインを適用しないため、ルート プロジェクトにはタスクがありません。)

于 2013-05-21T08:47:38.183 に答える