Problem description:
I'm using Gradle Shade plugin, it all works fine and it copies resource files to the final jar. However, as the docs say, it can not include other .jar files as resources because it can not distinguish them from dependencies. It unpacks them isntead.
What I want to do:
I want to copy extra .jar files from tools folder (which lives next to my build.gradle) into the final jar produced by shadowJar task.
Question:
How to extend a task (shadowJar) to copy additional files into the produced jar file.
This is answered in the documentation of the Gradle shadow plugin, section Embedding Jar Files Inside Your Shadow Jar:
Unfortunately, this holds both for a JAR that is part of a dependency configuration as well as copying a JAR using a
fromcopy spec (which works since theshadowJartask extends thejartask; which in turn is a copy task and hence supports copy specs).So, a JAR can only be embedded by renaming it. If it must be named
.jarinside the Uber JAR, I think the only option is a three-step workaround:*.zip.*.zipback to*.jar.jarorziptask.