这个 gradle/groovy 结构是什么意思?

What does this gradle/groovy structure mean?

我正在阅读一个 android gradle 构建文件,但我不明白其中的一些从语法角度是如何工作的,需要一些指导。我查看了 gradle 和 groovy 文档,但找不到我需要的内容。老实说,我什至不知道要搜索什么。

有问题的结构是这样的:

name {
  ...
}

我怀疑这与闭包有关,但我真的不知道这里发生了什么。该结构嵌入到另一个相同的结构中。这些是什么东西,口译员如何invoked/read/used?

你走在正确的轨道上。这是一个闭包,作为方法 name 的参数调用。

喜欢

 name({ /*...*/ })

See the docs for when to leave out parentheses.

方法 name 不能真正存在于该上下文中,因为这是 groovy DSL 中广泛使用的模式。 methodMissing 将改为调用。