Which from method I am calling on Copy Task?

I understand that when we are writing the following,

task newCopyTask(type: Copy){
    from 'image'                             // this line in question
	include '*.gif'
	into 'build'
}

I am calling the AbstractCopyTask from(Object... sourcePaths) method on Copy Task object on 2nd line.

But in case of the following,

task newCopyTask(type: Copy){
    from('image'){                             // this line in question
	    include '*.gif'
	    into 'gif'
    }

into 'build'
}

Am I calling this method AbstractCopyTask from(Object sourcePath, Closure c)?

If that is so, I do not understand how my arguments are lining up? Closure c is the 2nd argument, but it’s outside of parenthesis.

It’s a feature of Groovy: http://mrhaki.blogspot.com/2009/11/groovy-goodness-passing-closures-to.html

Groovy allows you to use that syntax if the last parameter is a Closure.

1 Like