User Guide: Clarify difference between "task hello << { ..." and "hello << { ..."

In section 57.2.1, “Defining common behavior”, I saw something that I imagine I’ve seen before, but I didn’t realize it. Here’s the code sample:

allprojects {
task hello << {task -> println "I'm $task.project.name" }
}
subprojects {
hello << {println "- I depend on water"}
}

The first part that defines the “hello” task uses the “task” keyword. The second segment configures part of the “hello” task, but it doesn’t use the “task” keyword. I’ve verified that the second piece is not able to use the “task” keyword. If I add that, it fails, saying it’s a duplicate task.

It appears that adding task configuration without the “task” keyword assumes that there is an occurrence of the “task” keyword for that task somewhere else, and this just augments that definition. This section where I first noticed this makes no mention of this.

Is this behavior documented somewhere else in the User Guide?

The former creates a new task and adds a task action, the latter adds a task action to a previously created task. I’d expect this difference (in particular that ‘task foo’ creates a task) to be documented somewhere.

See http://www.gradle.org/docs/current/userguide/userguide_single.html#N10222 and http://www.gradle.org/docs/current/userguide/userguide_single.html#sec:shortcut_notations

Generally everything is explained in the user guide somewhere. The problem is that it has grown so large and sprawling that it can be hard to find specific stuff. I think there is general agreement among the core team that the user guide needs an overhaul, it is just a matter of finding the time :slight_smile:

In the meantime any community contributions to documentation are gratefully received :wink: