Reputation: 8624
Being new to Gradle and Groovy, I'm having a hard time understanding the following piece of code I came across in the Writing a simple plugin tutorial:
class GreetingPlugin implements Plugin<Project> {
void apply(Project project) {
project.task('hello') {
doLast {
println 'Hello from the GreetingPlugin'
}
}
}
}
project.task('hello') {...}
? It looks like a method declaration without a return type or like a method call with additional brackets... what is this construct?doLast {...}
and where does it originate from? What syntax pattern is that anyway... some keyword followed by brackets. I cannot find anything like it in the Groovy syntax page, which mostly has examples of using ${}
or using brackets to define a class or method.Upvotes: 0
Views: 35
Reputation: 27958
In groovy, if the last argument to a method is a closure, you can put it outside the round brackets.
Eg
project.task('foo', {
doStuff()
})
Is equivelant to
project.task('foo') {
doStuff()
}
Here's the links to the javadocs for the two methods
Upvotes: 2