I am following the user guide at https://docs.gradle.org/5.0/userguide/multi_project_builds.html#multi_project_builds and trying to replicate the examples.
In a multi-project Gradle project, a task defined in the root project is modified in a subproject. When running the task from the subproject directory (subdirectory), Gradle complains that it doesn’t identify the task. It’s logical but the user guide assumes it will work fine and that is what is confusing. I hope someone can clarify this.
water/settings.gradle:
rootProject.name = ‘water’
include ‘bluewhale’,‘krill’,‘tropicalFish’
water/build.gradle:
allprojects {
task hello {
doLast{ task ->
println “I’m $task.project.name”
}
}
}
water/bluewhale/build.gradle
task hello.doLast{
println “- I’m the largest animal that has ever lived on this planet”
}
Console
water/bluewhale
$ ./gradlew.bat :hello
FAILURE: Build failed with an exception.
-
Where:
Build file ‘water\bluewhale\build.gradle’ line: 33 -
What went wrong:
A problem occurred evaluating root project ‘bluewhale’.
Could not get unknown property ‘hello’ for root project ‘bluewhale’ of type org.gradle.api.Project.
-
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. -
Get more help at https://help.gradle.org
BUILD FAILED in 1s