Tasks.withType doesn't apply to inline calls of Copy

I am trying to set some global configurations for common tasks like Copy. While tasks.withType works for any tasks of type Copy, configurations are not getting applied with copy closure inside a general task.

// custom configuration tasks.withType(Copy) {

… }

// works on these task customCopy(type: Copy) { }

// does not work here { task customCopy << {

copy {

} }

This is by design. The withType method works only on Task types (Class level). By just using the copy method within a default task, the type of the task is still DefaultTask. That’s why this task is not picked up by tasks.withType(Copy)

cheers, René

Thanks Rene. Is there a way to apply global configuration for copy method?

Is there a way to apply global configuration for copy method?

There isn’t at this time.

Why do you need to use the copy method instead of the task?

Well, there are many times when one atomic unit of work is more than a copy. Or instances when you have copy inside findAll.each for example.

What configuration do you want to apply to the method variants?

Sounds like you understand this, but just in case: It’s best to avoid using them as much as possible as they are not incremental.

fileMode.

Copy preserves the original file permissions which are generally read only as set by scm. Many times we want to override/overwrite files during incremental builds. I was wondering if I can somehow set rw file mode globally and not individually everywhere.

There’s no way to do this with the action variant.