I would like to split my app into 2 fat jars (modules/libraries).
I've checked already the "Spring Boot thin jar project", which loads the dependencies and caches them on first run but I cant make it work with multiple local modules.
Still... I would prefer to make my first approach work. Any ideas?
Gradle 6.9.1 (7.x not working with thin jar)
Spring Boot 2.6.x
Edited (2022-02)
Check my solution below...
CodePudding user response:
Create 2 projects, when build, build to 2 JAR file.
Project 1 (fat JAR) reference to Project 2.
Spring Boot fat JAR (has embed Tomcat), will call another JAR.
CodePudding user response:
I managed to do what I wanted.
For that purpose, I had to extend the bootJar task in gradle into 2 tasks, one for the dependencies, and one for my libraries...
task bootJarDeps(type: org.springframework.boot.gradle.tasks.bundling.BootJar) {
description "Generates JAR with just dependencies."
exclude 'com.mypackage.**.jar'
archiveName 'deps.jar'
mainClass = 'com.mypackage.App'
with bootJar
}
The mainClass in the dependencies is useless, but still required for the task.
task bootJarApp(type: org.springframework.boot.gradle.tasks.bundling.BootJar) {
description "Generates JAR without dependencies."
include 'com.mypackage.**.jar'
mainClass = 'com.mypackage.App'
archiveName 'app.jar'
with bootJar
}