What does << do?


(J.V.) #1

What is the difference between:

task hello { }

and

task hello << {

}

The docs do not clarify the difference and what << does http://www.gradle.org/docs/current/userguide/tutorial_using_tasks.html


(René Groeschke) #2

Hello,

could you wrap your code snippets in a <code> block?

In general the leftship operator (<<) is equivalent to the doLast method call.

This snippet:

task hello {
 }

creates a task named hello with an empty configuration block. it’s similar to

task hello

If you write

task hello << {
 }

you create a task with the name hello and add an action to that task which will be executed when the task is triggered by the build. It has exactly the same meaning as

task hello{
    doLast{
    }
 }

cheers, René


(J.V.) #3

thanks, that works.