-1

I'm using Gradle and I try to configure for my Android project. I read document and I see that there are two ways of defining a task.

Without << Operator

task SampleTask {
    methodA param1 param2
}

With << Operator:

Task SampleTask <<{
   methodA param1 param2
}

My question is: what is real differences between above 2 ways?

Thanks :)

hqt
  • 29,632
  • 51
  • 171
  • 250

1 Answers1

1

you can define tasks like this :

task hello {
    doLast {
        println 'Hello world!'
    }
}

here, the last thing that hello task does, is to print 'Hello World!' I can use another syntax for defining my task like this :

task hello << {
    println 'Hello world!'
}

these two tasks are same. another example is :

task hello << {
    println 'Hello Earth'
}
hello.doFirst {
    println 'Hello Venus'
}
hello.doLast {
    println 'Hello Mars'
}
hello << {
    println 'Hello Jupiter'
}

now the output will be :

Hello Venus
Hello Earth
Hello Mars
Hello Jupiter

read documentation for more details.

Mohammad Rahchamani
  • 5,002
  • 1
  • 26
  • 36