Where this task method comes from?

Hi, I am a new to gradle.

I have a question, the following code:
task(‘copy’, type: Copy) {
from(file(‘srcDir’))
into(buildDir)
}
Where this task method comes from? I can’t find it in the Project or from Script?

Thanks a lot.

It’s the Task task(Map<String, ?> args, String name, Closure configureClosure) method on Project that’s referenced here.

In the Groovy language (not specific to Gradle), named arguments are assigned to a Map, which must be the first parameter in the method declaration. The named arguments can appear in any location as long as the ordered arguments are still in the correct order, so the following are identical:

task('copy', type: Copy) {
    from(file('srcDir'))
    into(buildDir)
}
task(type: Copy, 'copy') {
    from(file('srcDir'))
    into(buildDir)
}
1 Like

Thanks @jjustinic, I understand now.