简体   繁体   English

此gradle / groovy结构是什么意思?

[英]What does this gradle/groovy structure mean?

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. 我正在阅读android gradle构建文件,但我从语法的角度不了解其中的某些工作原理,并且可以提供一些指导。 I've looked at the gradle and the groovy docs and can't find what I need. 我查看了gradle和groovy文档,找不到我需要的东西。 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 . 这是一个闭包,被称为方法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. 方法name在该上下文中一定不存在,因为这是常规DSL中广泛使用的模式。 methodMissing will be called instead. 将改为调用methodMissing

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM