Hi,
Am 11.01.11 21:40, schrieb Eric Nelson:
> I'm sorry if this is a newbie question, but what is the significance of the 
> << operator in Gradle scripts?  As an example:
>
> task hello << {
>       println "hello"
> }
task hello << {
    println "hello"
}

is just a shortcut for
-----
task hello {
    doLast{
        println "hello"
    }
}
-----

As you can read in the userguide
(http://gradle.org/0.9.1/docs/userguide/build_lifecycle.html), there is
a configuration phase and a execution phase. everything in a doLast{}
closure is executed during the execution phase. Simple tasks (as the
hello task above) don't need any configuration so the shortcut notation
is all you need. Some tasks need configuration. As a rule of thumb, the
configuration phase defines the WHAT, the execution phase takes care of
the HOW.

Let's take a look at a typical definition of a Copy task:
-----
task copyTask(type: Copy) {
    from 'src/main/webapp'
    into 'build/explodedWar'
}
-----
The task definition above tells gradle WHAT to copy. The HOW (the copy
action itself) is implemented in the Copy class. A refactored task that
prints to stdout and seperates WHAT and HOW can look like that:
-----
class PrintlnTask extends DefaultTask{
    def output;
   
   @TaskAction
    void print {
        println output
    }   
}

task hello(type: PrintlnTask) {
    output = "hello"
}
-----

regards,
René

-- 
------------------------------------
Rene Groeschke

[email protected]
http://www.breskeby.com
http://twitter.com/breskeby
------------------------------------


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to