-
Notifications
You must be signed in to change notification settings - Fork 40.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document using the Shadow plugin as an alternative to Boot's fat jars when using Gradle #1828
Comments
what do you mean not using the boot plugin? Are you creating a fat jar yourself? |
Yes, this is a requirement in certain environments such as Hadoop, Spark, Storm, etc. since they don't know how to load nested jars. Please see #1668 for more details on this topic. |
Here is the section in the docs im referring to |
Just hit an issue in a new Spring Boot version. I needed to amend the above to have: transform(PropertiesFileTransformer) { paths = ['META-INF/spring.factories' ] } This seemed to have resolved my issue. |
Final working example should be like that, strategy is required if you are using several components that contains spring.factories: import com.github.jengelman.gradle.plugins.shadow.transformers.*
shadowJar {
// Required for Spring
mergeServiceFiles()
append 'META-INF/spring.handlers'
append 'META-INF/spring.schemas'
append 'META-INF/spring.tooling'
transform(PropertiesFileTransformer) {
paths = ['META-INF/spring.factories' ]
mergeStrategy = "append"
}
}
I hope it will save someone's lot of time :) |
We're cleaning out the issue tracker and closing issues that we've not seen much demand to fix. Feel free to comment with additional justifications if you feel that this one should not have been closed. |
I think there might be some merit to doing something in this area. Spring Cloud Function (and FaaS in general) would benefit from an easy way to produce a shadowed jar. We really need something that's equivalent to the Maven Shade Plugin's configuration from the starter parent pom. That could take the form of documentation, or it could possibly take the form of some code in Boot's gradle plugin that sets up the various transformers. |
With the |
This comment has been minimized.
This comment has been minimized.
@unilama thanks for your comment. I was looking for this as Google's Dataflow also doesn't work with Spring's Fat-jar.
|
Another aspect of the Spring Gradle plugin that needs manually recreating is the exclusion of the I've found this the simplest way to recreate that:
Hopefully my reading of #26686 is correct and the |
Has this issue been addressed in spring-boot 2.7.5 ? I was using the shadowJar task defined above with my app that used spring-boot v2.6.6 but after upgrading to 2.7.5 looks like it stopped working and I had to remove shadowJar. Can anyone confirm if there was an effort to fix in 2.7.5 ? |
@ShalabhR This was a documentation issue, adding to Boot's reference documentation a link to the Shadow plugin. As such, there was nothing to fix. If you have a build that works with 2.6.6 and fails with 2.7.5, you may have found a regression. If you open a new issue and provide a minimal sample that reproduces the problem, we'll take a look. |
Because I struggled several hours solving my issue, here is what I have done with Spring Boot v3.0+ (but may work for v2.7+ as well... To be tested):
=> https://stackoverflow.com/q/74871072/10165346 This means that it is required to merge the This leads me to the following Gradle configuration for the shadowJar {
// Required for proper Spring Boot shading
mergeServiceFiles()
append("META-INF/spring.handlers")
append("META-INF/spring.schemas")
append("META-INF/spring.tooling")
append("META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports")
transform(PropertiesFileTransformer().apply {
paths = listOf("META-INF/spring.factories")
mergeStrategy = "append"
})
} Hope it will help. |
I found the following is required in Gradle to get a fat jar working when cannot use the
spring-boot-gradle-plugin
plugin: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.
The text was updated successfully, but these errors were encountered: