Closed
Description
I 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.