Gradle/Groovy语法混乱 [英] Gradle/Groovy syntax confusion
问题描述
有人能解释/评论这部分Groovy代码吗?
Can anyone explain/comment on this fraction of Groovy code?
task copyImageFolders(type: Copy) {
from('images') {
include '*.jpg'
into 'jpeg'
}
from('images') {
include '*.gif'
into 'gif'
}
into 'build'
}
关于或
from(sourcePath, configureAction)
如果是带有2个参数的那个,为什么要这样写而不是这样:
If its the one with the 2 arguments, why it’s written this way and not something like:
from('images', {
include '*.jpg'
into 'jpeg'
})
推荐答案
简短的答案是它正在调用from(sourcePath, configureAction)
.
The short answer is it's calling from(sourcePath, configureAction)
.
Groovy在许多情况下都具有可选的括号,并接受括号之外的最后一个参数(如果是闭包),在这种情况下,这就是您要传递给from()
的闭包.
Groovy has optional brackets in a number of cases and accepts the last parameter (if it's a closure) outside of brackets and in this case that's the closure that you're passing to from()
.
这是一个不错的博客帖子解释了如果需要更多示例以及此通常提供更多可选括号的示例.
This is a good blog post explaining the different ways a closure can be passed to a method in Groovy if you want more examples and this offers more examples of optional brackets in general.
这篇关于Gradle/Groovy语法混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!