[英]Gradle dependencies groovy closure syntax
Very basic question. 非常基本的问题。
This snapshot in build.gradle
: 这个快照在
build.gradle
:
dependencies {
classpath 'com.android.tools.build:gradle:0.13.2'
}
is supposed to call method dependencies(Closure c)
and pass it a closure. 应该调用方法
dependencies(Closure c)
并将其传递给闭包。
Could someone please explain the syntax of this simple closure { classpath 'com.android.tools.build:gradle:0.13.2' }
有人可以解释一下这种简单关闭的语法
{ classpath 'com.android.tools.build:gradle:0.13.2' }
It is not returning anything, is it ? 它没有返回任何东西,是吗?
http://groovy.codehaus.org/Closures+-+Formal+Definition http://groovy.codehaus.org/Closures+-+Formal+Definition
Notably: 值得注意的是:
Closures always return a value.
闭包总是返回一个值。 This may occur via either an explicit return statement, or as the value of the last statement in the closure body (eg an explicit return statement is optional).
这可以通过显式return语句发生,也可以作为闭包主体中最后一条语句的值发生(例如,显式return语句是可选的)。
There's not really any syntax to explain; 确实没有任何语法可以解释。 there's a closure, inside it the
classpath
method is called, and it takes a string argument. 有一个闭包,里面有一个
classpath
方法,它带有一个字符串参数。 Whether or not anything is done with the return value, or whether or not the return value is significant , is a separate issue. 是否对返回值执行任何操作 ,或者返回值是否有意义 ,是一个单独的问题。
In this case it's not; 在这种情况下不是这样。 there's a side-effect of setting the classpath value.
设置类路径值会有副作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.