DuplicationsStrategy Clarification

The java doc for DuplicatesStrategy (DuplicatesStrategy (Gradle API 8.7)) says the default is INHERIT which means to “inherit the strategy from the parent copy spec”. What the heck is a “parent copy spec” and how do I set the duplicates strategy in the “parent copy spec”?

Copy specs are hierarchical.
If you for example have

val foo by tasks.registering(Sync::class) {
    into("...") {
        into("...") {
            from("...")
        }
    }
}

then the Sync task instance itself is the root copy spec, within the into you are in a child copy spec, within the second into you are in a grand-child copy spec.

But actually in most cases where you are tempted to use a duplicates strategy, you actually should not. In almost all cases out there, it is a much better idea to find out why there are duplicate files and fix the problem there at the root instead of using a duplicates strategy to work-around the symptom.

I would like to fix the duplicate but it seems to be coming from spring boot’s bootJar task, so not sure it is within my power to fix.

I am still not sure what you mean by “Copy specs” though. Does “spec” stand for specification? Are copy specifications just copy tasks? I think the documentation would benefit from a definition of the term “copy spec”.

It should be within your powers, yes.
You control what comes into that jar one way or another.

Does “spec” stand for specification?

Yes

Are copy specifications just copy tasks?

No

I think the documentation would benefit from a definition of the term “copy spec”.

I’d say its documentation is quite clear about that: CopySpec (Gradle API 8.7)

It is not clear at all because it does not indicate that “copy spec” is an interface. How does “inherit the strategy from the parent copy spec” suggest to anyone that there is an interface named CopySpec? There is nothing in the DuplicatesStrategy JavaDoc that links to the CopySpec JavaDoc. So I have no idea why you think that is clear. How would one arrive at the CopySpec javadoc from that verbiage in the DuplicatesStrategy javadoc?

I would say a link is in order. Or at least change it to “from the parent CopySpec”, that would at least give a clue that it might be an interface or class that might want to be searched for.

I did end up finding the cause of the duplicate though and fixed it.

It is not clear at all because it does not indicate that “copy spec” is an interface.

Yeah, starting from the duplicates strategy JavaDoc you are right, there is a link missing I’d say.
Feel free to open a PR or change request, I’m just a user like you. :slight_smile:

I did end up finding the cause of the duplicate though and fixed it.

:ok_hand: