I'm reading an android gradle build file and I don't understand how some of it works from a syntax perspective and could do with some guidance. I've looked at the gradle and the groovy docs and can't find what I need. To be honest, I don't even know what to search for.
The structure in question is this:
name {
...
}
I suspect that it's something to do with closures, but I really don't know what's going on here. This structure is embedded in another identical structure. What are these things, and how are they invoked/read/used by the interpreter?
You are on the right track. This is a closure, that gets called as parameter to the method name
.
Like
name({ /*...*/ })
See the docs for when to leave out parentheses .
The method name
must not really exist in that context as this is a widely used pattern in groovy DSLs. methodMissing
will be called instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.