Im playing around with gradle multi-project building with the STS plugin for Eclipse. I thought I got the basics after reading the tutorial, but I am not able to reproduce the shown behaviour. When adding
allprojects {
task hello << {task -> println "I'm $task.project.name" }
}
subprojects {
hello << {println "- I GradleMaster"}
}
to build.gradle of the parent project I would assume the task 'hello' being excuted for each project. For the subprojects actually 2 times, but the result is only:
[sts] -----------------------------------------------------
[sts] Starting Gradle build for the following tasks:
[sts] :hello
[sts] -----------------------------------------------------
:hello
I'm GradleMaster
BUILD SUCCESSFUL
My project tree looks more or less like this:
Application/
GradleMaster/
build.gradle
settings.gradle
EAR/
build.gradle
EJB/
build.gradle
AppClient/
build.gradle
GradleMaster/settings.gradle:
include ':EAR', ':EJB', ':AppClient'
As you see the parent project is on the same level as the subprojects. I already had it the other way with the root project at a higher level, but I couldn't notice any difference.
I'm also wondering how gradle behaves when executing tasks on the root project that all projects have in common. For example shouldn't 'clean' on the root project cause all subprojects to also execute their version of 'clean' if the all apply the 'base' plugin?
When writing the question I did not think about it might be an issue with the Eclipse STS plugin rather than with Gradle itself. In fact I did not even mention that I was using Gradle with Eclipse, which made the question almost impossible to answer.
It turned out be the way the STS plugin calls the tasks. There are tasks and task selectors. Calling the task performs the task only in the project, whereas calling the task selector performs all task of the same name in the multi-build project.
st_oehme's post in the Gradle forum took me to the right track.
I don't have Eclipse with Gradle STS installed anymore, so I cannot tell you exactly what you have to do to call the task selector instead of a single task. Maybe someone else could add that...