GradleUp / shadow

Gradle plugin to create fat/uber JARs, apply file transforms, and relocate packages for applications and libraries. Gradle version of Maven's Shade plugin.
https://www.gradleup.com/shadow/
Apache License 2.0
3.69k stars 389 forks source link

Can't use the same module name as archive file name for the jar file #921

Open EchoEllet opened 4 months ago

EchoEllet commented 4 months ago

Shadow Version

8.1.1

Gradle Version

8.7

Expected Behavior

Should we be able to use the same module name as jar file? let's say you have a module name called example-module-name and the jar file name would be example-module-name.jar

Actual Behavior

If you use the following:


tasks.withType(com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar::class) {
    archiveFileName.set("example-module-name.jar")
}

and run ./gradlew build you will get the following error:


FAILURE: Build failed with an exception.

* What went wrong:
Some problems were found with the configuration of task ':example-module-name:shadowJar' (type 'ShadowJar').
  - Gradle detected a problem with the following location: '/Users/yourusername/Developer/projects/yourproject/example-module-name/build/libs/example-module-name.jar'.

    Reason: Task ':example-module-name:distZip' uses this output of task ':example-module-name:shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

    Possible solutions:
      1. Declare task ':example-module-name:shadowJar' as an input of ':example-module-name:distZip'.
      2. Declare an explicit dependency on ':example-module-name:shadowJar' from ':example-module-name:distZip' using Task#dependsOn.
      3. Declare an explicit dependency on ':example-module-name:shadowJar' from ':example-module-name:distZip' using Task#mustRunAfter.

    For more information, please refer to https://docs.gradle.org/8.7/userguide/validation_problems.html#implicit_dependency in the Gradle documentation.
  - Gradle detected a problem with the following location: '/Users/ellet/Developer/projects/minecraft-sync/example-module-name/build/libs/example-module-name.jar'.

    Reason: Task ':example-module-name:distTar' uses this output of task ':example-module-name:shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

    Possible solutions:
      1. Declare task ':example-module-name:shadowJar' as an input of ':example-module-name:distTar'.
      2. Declare an explicit dependency on ':example-module-name:shadowJar' from ':example-module-name:distTar' using Task#dependsOn.
      3. Declare an explicit dependency on ':example-module-name:shadowJar' from ':example-module-name:distTar' using Task#mustRunAfter.

    For more information, please refer to https://docs.gradle.org/8.7/userguide/validation_problems.html#implicit_dependency in the Gradle documentation.
  - Gradle detected a problem with the following location: '/Users/ellet/Developer/projects/minecraft-sync/example-module-name/build/libs/example-module-name.jar'.

    Reason: Task ':example-module-name:startScripts' uses this output of task ':example-module-name:shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

    Possible solutions:
      1. Declare task ':example-module-name:shadowJar' as an input of ':example-module-name:startScripts'.
      2. Declare an explicit dependency on ':example-module-name:shadowJar' from ':example-module-name:startScripts' using Task#dependsOn.
      3. Declare an explicit dependency on ':example-module-name:shadowJar' from ':example-module-name:startScripts' using Task#mustRunAfter.

    For more information, please refer to https://docs.gradle.org/8.7/userguide/validation_problems.html#implicit_dependency in the Gradle documentation.

Content of Shadow JAR (jar tf <jar file> - post link to GIST if too long)

I can't get the jar builded

Goooler commented 4 months ago

The stacktrace shows clearly, try

tasks.named("distZip") {
    dependsOn(tasks.withType(com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar::class))
}
EchoEllet commented 4 months ago

The stacktrace shows clearly, try

tasks.named("distZip") {
    dependsOn(tasks.withType(com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar::class))
}

Thank you, I will try that, but I'm not sure how it's related to distZib task (it could be that shadowJar depends on distSize but that's already by default). This error only shows when using the exact same module name + .jar