Why is gradle generating 2 jars after update to gradle 7.3.2

I updated gradle to 7.3.2 and shadow plugin: id "com.github.johnrengelman.shadow" version "7.1.1". With gradle 6 and older version of shadow 1 single fat jar was generated after running gradle build. Now I get 2 jars, 1 jar which does not contain other libs and a fat jar called "...-all.jar". In my build I have this line:

build.dependsOn.add("shadowJar")

Why is that so and how do I get only 1 fat jar without the -all extension?

One thing to note: I am not sure if this is a false warning but IntelliJ shows on "dependsOn" the following warning:

No candidates found for method call build.dependsOn.
  myProject.myModule

Solution 1:

There will be two JARs: one from the task jar and the other from shadowJar. The former only contains bytecode of your source code, while the latter not only bytecode but also JARs from third parties.

You got single JAR in the old version because the two JARs' filenames are the same. The one produced by shadowJar simply overwrite the other. You can keep checking its size during ./gradlew build. I think this behavior was a bug in the Shadow plugin, and later fixed in the newer versions. I noticed it because it only happened in Linux, not in MacOS (or in MacOS not in Linux, I just can't remember). This JAR overwriting did affect the Gradle cache mechanism.

You can change the output name by setting archiveClassifier:

shadowJar {
   archiveClassifier.set('')
}

References

  • https://imperceptiblethoughts.com/shadow/configuration/#configuring-output-name