I’ve recently been using the properties task to validate that some changes to my build are having the desired effect on my build properties.
I notice that when I call the properties task on the top-level project of a multi-project build, it only returns the properties for the top-level project. This behavior is surprising to me, since based on Gradle’s documentation, I would expect a task executed by name at the top level to be also called on all subprojects:
The command
gradle test
will execute thetest
task in any subprojects, relative to the current working directory, that have that task. If you run the command from the root project directory, you’ll runtest
in api , shared , services:shared and services:webservice . If you run the command from the services project directory, you’ll only execute the task in services:shared and services:webservice.The basic rule behind Gradle’s behavior is: execute all tasks down the hierarchy which have this name. Only complain if there is no such task found in any of the subprojects traversed.
Is there something wrong with my understanding of how this should work? Is there something special about the properties task where it doesn’t also apply to the subprojects?
My main goal with this question is to gain a better understanding of how Gradle works. That said, a way to apply the properties task to the subprojects would be welcome as well. I’ve created a similar Stack Overflow question with that focus, rather than the “why”.
Edit: I see that the documentation for the dependencies task states that will only execute in a single project.
The
dependencies
task will only execute on a single project. If you run the task on the root project, it will show dependencies of the root project and not of any subproject. Be sure to always target the right project when runningdependencies
.
Is this the same situation/mechanism used with the properties task, just not documented (or not documented where I’ve seen)? Why do these tasks not recurse to subprojects?