Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for the usages of DuplicatesStrategy #520

Closed
bsideup opened this issue Oct 22, 2019 · 4 comments · Fixed by #1343
Closed

Add docs for the usages of DuplicatesStrategy #520

bsideup opened this issue Oct 22, 2019 · 4 comments · Fixed by #1343

Comments

@bsideup
Copy link

bsideup commented Oct 22, 2019

Hi!

It would be very helpful to be able to exclude files but only if they come from dependencies, not project's. Some examples:

  • META-INF/LICENSE
  • META-INF/NOTICE
  • META-INF/versions/9/module-info.class

If we exclude them with the current API, project's files will also get excluded from the final JAR, but that's very undesired.

Thank you!

@AHeise
Copy link

AHeise commented Jan 30, 2020

You can achieve this by using:

tasks.withType<ShadowJar> {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

Your stuff is added first to the jar and everything with the same path that comes later is simply ignored.

@Marcono1234
Copy link
Contributor

Slightly related to #710, which is only about module-info.class coming from the project.

@Steve973
Copy link

Steve973 commented Feb 3, 2025

You can achieve this by using:

tasks.withType<ShadowJar> {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

Your stuff is added first to the jar and everything with the same path that comes later is simply ignored.

This behavior is not clear, and that is at least part of the problem. If we set aside, for the moment, our respective preferences in how this plugin should behave, the documentation does not seem to discuss this at all. If we are configuring our project to produce a module-info.class file, we expect that this file would be included in the jars that we produce. This is a specifically intentional configuration. When we want to roll anywhere between one and all of our dependencies in our jar, there is no reason why we would think that our JPMS configuration should be omitted. If the issue is that module-info.class collides with a dependency's module-info.class and is, therefore, entirely left out, there is no warning in the build that brings any attention to this. It is silently dropped on the floor.

I have tried your recommended workaround, but even when including the configuration to exclude duplicates, it still drops the module-info.class file in the root of the jar in the plugin version 8.3.5 and 9.0.0-beta7. I am really struggling to understand why this is the deliberately chosen behavior.

@Goooler
Copy link
Member

Goooler commented Feb 28, 2025

module-info.class is excluded by default in

I believe you can try out

tasks.shadowJar {
  excludes.remove(
    "module-info.class"
  )
  duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

with 9.0.0-beta9, see #1298.

@Goooler Goooler changed the title Support source exclusions Add docs for the usages of DuplicatesStrategy Mar 3, 2025
@Goooler Goooler changed the title Add docs for the usages of DuplicatesStrategy Add docs for the usages of DuplicatesStrategy Mar 3, 2025
@Goooler Goooler marked this as a duplicate of #710 Mar 3, 2025
UpcraftLP added a commit to QuiltMC/quilt-installer that referenced this issue Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants