Gradle 7 Fail for duplicates in copy specs: Has no duplicates in project

With Gradle 7 now my copy resources task fails.
It complains about duplicate files.

I solved it by adding duplicatesStrategy = 'include' to my Copy task, after checking the Gradle 7 Release Note where this change is mentioned.

However I find it strange though, since the files it complains about has no duplicates.

> Entry application-viewer.desktop is a duplicate but no duplicate handling strategy has been set. Please refer to https://docs.gradle.org/7.0/dsl/org.gradle.api.file.CopySpec.html#org.gradle.api.file.CopySpec:duplicatesStrategy for details.

> Entry preuninstall is a duplicate but no duplicate handling strategy has been set. Please refer to https://docs.gradle.org/7.0/dsl/org.gradle.api.file.CopySpec.html#org.gradle.api.file.CopySpec:duplicatesStrategy for details.

These are files used by jpackage tool. This tool has template for these files, but they are not in my project.

Can you please elaborate more on how and where you added duplicatesStrategy = 'include'?

When I add it to my e2eTest task in my build.gradle I get the following error:

 Could not set unknown property 'duplicatesStrategy' for task ':e2eTest' of type org.gradle.api.tasks.testing.Test

I added duplicatesStrategy to my Copy task.

task processPackageResources(type: Copy) {
    ....

    duplicatesStrategy = 'include'
}

Thank you! I mistakenly added it to a e2eTest(type: Test) task.

I didn’t have a copy task, so I added a new one:

task processPackageResources(type: Copy) {
    duplicatesStrategy = 'include'
}

but that hasn’t solved the issue, I am still getting the error:

Entry application.properties is a duplicate but no duplicate handling strategy has been set. Please refer to https://docs.gradle.org/7.0.2/dsl/org.gradle.api.tasks.Copy.html#org.gradle.api.tasks.Copy:duplicatesStrategy for details.
Task :processE2eTestResources FAILED
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':processE2eTestResources'.

Seems you need it on the processE2eTestResources, but that is probably not a task you have defined, but Gradle has.

Exactly! It is defined by Gradle. So how do I solve this issue?

This appears to be currently an unresolved issue.

It doesn’t matter whether you defined it, a third-party plugin defined it, or something in the Gradle core defined it. Nothing stops you from configuring an existing task regardless of where it was defined. Once it’s defined, you can reference it directly, or use tasks.named(...) if you’re making use of the configuration avoidance APIs.

1 Like

Thank you for the tip :slight_smile: I was not aware of such feature. But it helped me to resolve the issue.

rootProject.tasks.named("processApiTestResources") {
    duplicatesStrategy = 'include'
}

Hi,
Faced the similar issue when creating fat jar.

Adding duplicatesStrategy = ‘include’ inside fatJar task worked in my case.

task fatJar(type: Jar) {
duplicatesStrategy = ‘include’


}