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

(Abhishek Nath) #1

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 {

} }

(René Groeschke) #2

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é

(Abhishek Nath) #3

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

(Luke Daley) #4

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?

(Abhishek Nath) #5

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.

(Luke Daley) #6

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.

(Abhishek Nath) #7


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.

(Luke Daley) #8

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