Gradle 7.x and DuplicatesStrategy

I keep having to add a DuplicatesStrategy DSL block to builds to get them to work under Gradle 7.x.

Here is an example:

Execution failed for task ':processResources'.
> Entry README.md is a duplicate but no duplicate handling strategy has been set. Please refer to https://docs.gradle.org/7.2/dsl/org.gradle.api.tasks.Copy.html#org.gradle.api.tasks.Copy:duplicatesStrategy for details.

There is only one README.md in this particular project so why is there a duplicate? Can someone clarify what this means by “duplicate”? What is it a duplicate in? By “duplicate” does it mean it is being included in more than one sourceSet? How do I make it not be a duplicate?

Also, the JavaDoc linked to in the error message says DuplicatesStrategy defaults to INHERIT. The error messages says “but no duplicate handling strategy has been set”, but a default exists so why do I have to set it explicitly?

Hi,

There is only one README.md in this particular project so why is there a duplicate?

It seems like the README.md file is included twice in the copy spec instead of once. That is why Gradle detects it as a duplicate. Gradle currently doesn’t check whether the duplicates are identical, which would probably be the case for you.

Also, the JavaDoc linked to in the error message says DuplicatesStrategy defaults to INHERIT. The error messages says “but no duplicate handling strategy has been set”, but a default exists so why do I have to set it explicitly?

The default duplicates strategy is INHERIT, and I think the Javadoc there is wrong now:

     * The default strategy, which is to inherit the strategy from the parent copy spec, if any,
     * or {@link DuplicatesStrategy#INCLUDE} if the copy spec has no parent.

I think it should be

     * The default strategy, which is to inherit the strategy from the parent copy spec, if any,
     * or {@link DuplicatesStrategy#FAIL} if the copy spec has no parent.

Cheers,
Stefan

Ok, but how do I fix it? The processResources task appears to come from the built-in java plugin. How do I keep that plugin from including README.md twice in the copy spec?

Ok, but how do I fix it? The processResources task appears to come from the built-in java plugin. How do I keep that plugin from including README.md twice in the copy spec?

Where does the README.md reside in your build and how is the processResources task configured to process it? Is the file in src/main/resources or somewhere else and then added as a resource directory? I would expect that the same resource dir is maybe added twice for some reason?

Cheers,
Stefan

Sorry it took me a while to respond, I don’t get notifications about responses.

The offending build is actually this build of an example game with the litiengine game engine:

The README.md is at the root level.

I have the build working by specifying a DuplicatesStrategy of EXCLUDE but just trying to get a grasp on why that would be duplicated (because I have similar issues with some of my own builds).

They use a non-standard layout so have resource directories specified in a source set, but the root directory isn’t included in it.

main.resources.srcDirs = ["sprites", "audio", "maps", "misc"]

In that example project sprites, audio, and maps all contain a README.md.

Embarrassingly I never actually looked in any of those directories to see if there might be a README in there. Thanks for that pointer.