Gradle Copy task issue with duplicate file

Hello Team,

in build.gradle I have following code:

task copyModifiedSources(type:Copy) {
    from ('ApiClient.java.modified') {
        rename 'ApiClient.java.modified', 'ApiClient.java'
    }
    setDuplicatesStrategy(DuplicatesStrategy.INCLUDE)
    into 'build/generated/src/main/java/com/client/invoker'
}

I am trying to copy ApiClient.java.modified (renamed to ApiClient.java before copy) file into build/generated/src/main/java/com/client/invoker folder which already has ApiClient.java file.
I am using a duplicate strategy to override APIClient.java from /invoker folder with ApiClient.java.modified.

If I renamed the copying file to the file name, not in /invoker folder then it works but does not work with the duplicate file name. The file is not copied successfully.

Could you please help me to figure out what is going wrong?

Gradle -> 6.5.1
Java -> 11

Thank you,

It sounds like you have two tasks copying files to the same destination folder. Don’t do this. Each task should have its own, separate, outputs