ksrb
ksrb

Reputation: 1945

Gradle Task creation

Problem

In a build.gradle script I get that:

 task 'myTestStr', {}         // is the same as
 Project.task('myTestStr, {}) // <-- this

But I don't get what:

task myTest(){} //invokes on the Project instance?

I'm learning Gradle and Groovy coming from a Java background so I'm pretty sure I'm missing some groovy-ness that explains this magic.

Additional Details

Using Intellij to Find Declaration (Ctrl + b) over myTest(){} says that it invokes TaskContainer#create(java.lang.String)

Upvotes: 1

Views: 66

Answers (1)

Opal
Opal

Reputation: 84884

It invokes exactly the same. If in a method declaration closure is the last argument it can be passed after the closing paren.

For instance inject method:

assert 1*1*2*3*4 == [1,2,3,4].inject(1) { acc, val -> acc * val }
assert 1*1*2*3*4 == [1,2,3,4].inject(1, { acc, val -> acc * val })

Upvotes: 1

Related Questions