Gradle/Groovy语法混乱 [英] Gradle/Groovy syntax confusion

查看:118
本文介绍了Gradle/Groovy语法混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能解释/评论这部分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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆