Sub-projects don't take on their parents' default tasks when Gradle runs from subdir?

I’m not sure I understand default task inheritance. The Gradle docs say: “In a multi-project build every subproject can have its own specific default tasks. If a subproject does not specify default tasks, the default tasks of the parent project are used (if defined).”

I tested this with the following code. A root project (“projectA”):

defaultTasks 'a'
  task a {}

A child project (":projectA:childProject") :

task a {}

And a settings.gradle file:

include "childProject"

If I run “gradle” from the root project, both “a” tasks get executed. If I run “gradle” from the child project, however, no tasks are executed:

root: a
child: a

Why does the sub-project only take on the root default tasks if executed from the root?

Is this expected / default behavior?

Sounds like a bug to me. You should be able to work around with something like ‘allprojects { defaultTasks ‘a’ }’.