Gradle: Build 'fat jar' with Spring Boot Dependencies
You don't need to make yourself additional gradle configurations for building a fat-jar artifact of spring-boot application, since you use a gradle spring boot plugin. It already has a task bootRepackage
to do it for you. You can read about it in official user guide here and here.
Just delete all you've done to unzip dependencies content and use this task to get a single jar file with your application.
By the way, you may be interested to look at some other solution, which possibly could provide a better archive sizes, you can read about one of them, called Capsule, in this article.
With current versions of gradle, add this at the top of your build.gradle
file:
plugins {
id "org.springframework.boot" version "2.0.0.RELEASE"
}
then just gradle build
- you don't need to do anything more.
See this plugin's homepage to find the latest version.
I found this link from @Stanislav's answer: https://docs.spring.io/spring-boot/docs/2.2.6.RELEASE/gradle-plugin/reference/html/#packaging-executable-wars-deployable to be very helpful.
To to build the jar, I used the bootJar
task to compile the jar. (./gradlew bootJar
). My project doesn't have the bootRepackage
task and using a ./gradlew build
did not generate a jar with all the dependencies it needed. Maybe that's something I should try to configure using something like dependsOn
, but for now this works for me.
I have a multimodule project, so maybe configuration is different for single module projects. I'm also using com.graphql-java:graphql-java-spring-boot-starter-webmvc:1.0
in my dependencies plus a few of the regular sping boot dependencies, so my set up isn't completely vanilla.