Gradle/Groovy syntax confusion

后端 未结 2 1451
青春惊慌失措
青春惊慌失措 2021-01-16 05:06

Can anyone explain/comment on this fraction of Groovy code?

task copyImageFolders(type: Copy) {
    from(\'images\') {
        include \'*.jpg\'
        into         


        
2条回答
  •  礼貌的吻别
    2021-01-16 05:35

    It's Syntactic Sugar, to make things easier to read (very useful for Gradle configuration)

    In this case it's all about parentheses.

    When a closure is the last parameter of a method call, like when using Groovy’s each{} iteration mechanism, you can put the closure outside the closing parentheses, and even omit the parentheses:

    list.each( { println it } )
    list.each(){ println it }
    list.each  { println it }
    

    In your case, everything below is working fine :

    from('images', {
        include '*.jpg'
        into 'jpeg'
    })
    
    from('images') {
        include '*.gif'
        into 'gif'
    }
    
    from 'images', {
        include '*.gif'
        into 'gif'
    }
    

提交回复
热议问题