Document using the Shadow plugin as an alternative to Boot's fat jars when using Gradle
See original GitHub issueI found the following is required in Gradle to get a fat jar working when cannot use the spring-boot-gradle-plugin
plugin:
import com.github.jengelman.gradle.plugins.shadow.transformers.*
// Can't use Boot's nested jar packaging due to environment constrained classloader
apply plugin: 'com.github.johnrengelman.shadow'
shadowJar {
zip64 true
exclude 'META-INF/*.SF'
exclude 'META-INF/*.DSA'
exclude 'META-INF/*.RSA'
// Required for Spring
mergeServiceFiles()
transform(AppendingTransformer) { resource = 'reference.conf' }
transform(AppendingTransformer) { resource = 'META-INF/spring.handlers' }
transform(AppendingTransformer) { resource = 'META-INF/spring.schemas' }
transform(AppendingTransformer) { resource = 'META-INF/spring.tooling' }
transform(PropertiesFileTransformer) { paths = ['META-INF/spring.factories' ] }
// ...
}
The docs should strongly recommend the shadow
/ shade
plugins for environmentally constrained classloaders¹ because resource transformation is a requirement. Without it, essential beans such as converters, property placeholder configurers, etc. go missing from Spring Boot’s autoconfiguration (i.e. spring.factories
). The result is very difficult to diagnose.
¹environmentally constrained classloaders: A system classloader not under your control.
Issue Analytics
- State:
- Created 9 years ago
- Comments:13 (5 by maintainers)
Top Results From Across the Web
what's the gradle alternative to a fat JAR? - java - Stack Overflow
The easiest way to create a fatjar in gradle, is to use the shadow plugin available via the plugin portal. see ...
Read more >Creating fat JARs using the Ktor Gradle plugin
The Ktor Gradle plugin allows you to create and run an executable JAR that includes all code dependencies (fat JAR).
Read more >Self-contained, executable Jars with Gradle and Shadow
Describes how to use Gradle and it's Shadow plugin to create a self contained, executable Jar. No more classpath management.
Read more >Introduction - Imperceptible Thoughts
Shadow is a Gradle plugin for combining a project's dependency classes and resources into a single output Jar. The combined Jar is often...
Read more >How to include dependencies in jar? - #21 by shrinathk
You might be interested in using the Shadow plugin. It generates a “fat-jar”, which is a Jar with the necessary dependencies. Note that...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Final working example should be like that, strategy is required if you are using several components that contains spring.factories:
I hope it will save someone’s lot of time 😃
@unilama thanks for your comment. I was looking for this as Google’s Dataflow also doesn’t work with Spring’s Fat-jar. For KotlinDSL, here’s what I had to do to make it work -