I am new to Gradle and ShadowJar. I am building an api project that is internally using a dropwizard framework. It’s a Java project. There are a bunch of dependencies that have same files under META-INF/services/
. When my application loads it fails to properly configure one of the auto-discoverable services and fails miserably. I learned that shadowJar can be of help in this situation. Now I’m struggling to make some sense out of how it can be integrated. Here is what I have in my build.gradle
file:
jar {
zip64 true
from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } }
manifest {
attributes(
'Main-Class': mainClassName,
'version': project.version,
'lastBuild': buildTime()
)
}
}
shadowJar {
mergeServiceFiles()
}
I build my project in the console by specifying: ./gradlew assemble
As the gradle outputs info while building, it doesn’t indicate invoking of the shadowJar
task. It shows calling jar
task, and I’d like assemble
to invoke shadowJar
.
When I invoke ./gradlew shadowJar
it builds a fat shadowed jar with merged service files (however, this process also merges other duplicates, such as META-INF/LICENSE.txt
and javax/annotation/CheckForNull.class
. In the original fat jar I see multiple instances of these classes, whereas in the shadowed jar there is only one instance per unique class. I do not know if this is normal defaulted behaviour or not).
Question: Is there a way to invoke shadowJar
task automatically when running assemble
? And what should be done for it?