Ask some questions about the block scripts execut?

(ren) #1

1.i can’t understand which task(*) method invoked when i write the block script “task myTask(type: SomeType) { configure closure }”.is it groovy syntax?

2.ext{ } has the same doubt,is it Project object block script? and in Project api don’t find ext.

please help me answer the questions.and i want to know some source code execute details.

(Sterling Greene) #2

It’s not purely Groovy, there’s an extra AST transform that takes

task myTask(type: SomeType)

and turns it into (so you don’t have to use quotes):

task("myTask", type: SomeType)

But ignoring that, the mapping is:

task myTask -> Project.task(String)

task myTask {} -> Project.task(String, Closure)

task myTask (type: SomeType) -> Project.task(Map, String)

task myTask (type: SomeType) {} -> Project.task(Map, String, Closure)

The last two take advantage of a Groovy feature (which give you something like named parameters). You can see an example here.

ext is a built-in extension called ExtraPropertiesExtension. A lot of types have this extension built-in. ext and property look-up in general are described in the DSL guide for Project. It relies on some of the dynamic properties of Groovy (methodMissing or propertyMissing methods) to look-up things properly.