Reputation: 1775
I have the following project structure:
application/build.gradle:
apply plugin: 'java'
settings.gradle:
include ':application'
build.gradle:
task custom << {
project.tasks.getByName("build").execute()
}
So I want to execute task "build" inside task "custom". But when I run "gradle custom" the result is:
: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
How I can execute the task "build" inside task "custom" ?
Upvotes: 8
Views: 19583
Reputation: 123890
You cannot. Task execution is declarative, not imperative. Tasks depend on each other, they do not execute each other. (Also, since you don't apply the Java (base) plugin in the root build script, the root project doesn't have a build
task.)
Upvotes: 8