Running tasks on nested subprojects

Let’s assume that I have the following project structure:

:API:Payment:Card
:API:Payment:Cash
:API:BackOffice:StockKeeping
:Client:PointOfSale
:Server:StockLedger

How can I chose to run a task on all subprojects that are nested underneath a specific subproject?

For example, if I want to run compileJava on all the subprojects under :API, how do I achieve that?

I have tried gradlew :API:compileJava, but that only attempts to run the compileJava task on :API, and none of it’s nested subprojects.

It’s worth noting that the :API project does not apply the java plugin, given it does not contain any Java code. Instead, it contains the nested subprojects, which themselves apply the java plugin and contain code.

You can use gradle -p API compileJava. This will behave just like calling Gradle in that subdirectory.

We have planned a better solution for this, which will probably look like this: gradle API::compileJava ( note the double colon). I don’t yet have a target version for that feature though.