'Running only the root task but not the subproject's tasks unless specified in a multi-project setup

I have a multi-project gradle with this structure:

root
:proj1
:proj2

I also have a task called mytask in all 3 projects.

Currently if I do gradle mytask all 3 tasks runs:

:mytask
:proj1:mytask
:proj2:mytask

I know that if I run gradle :mytask only the the root mytask run.

However I would like to:

  • gradle mytask runs only the root :mytask
  • gradle mytask proj1:mytask runs both tasks (root & prod1) but not :proj2:mytask

Note that this is the standard behaviour of the gradle native task properties :

  • gradle properties runs only the root :properties
  • gradle properties myproj:properties runs both (root & proj1) but not :proj2:properties


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source