I have done the migration of the Spring Boot Application from 1.5.8 to 2.1.14-RELEASE and using gradle as a build script. I am using spring-boot-gradle-plugin and spring-boot-dependency-management plugins. In our spring boot project, we are creating multiple executable jar files by creating tasks for each jar as below
// During Migration changed from Jar to BootJar
task eurekaAppJar(type: BootJar) {
baseName = 'eurekaJar'
version = '0.0.1'
println sourceSets.main.output
manifest {
attributes 'Main-Class': "org.springframework.boot.loader.JarLauncher"
attributes 'Start-Class': "com.abc.abcCompany.service.eurekaApp.EurekaApplication"
attributes 'Implementation-Version': "001"
}
bootJar {
mainClassName = "com.abc.abcCompany.service.eurekaApp.EurekaApplication"
}
from(sourceSets.main.output) {
}
}
// During Migration changed from Jar to BootJar
task oAuthConfigJar(type: BootJar) {
baseName = 'oAuthConfigJar'
version = '0.0.1'
manifest {
attributes 'Main-Class': "org.springframework.boot.loader.JarLauncher"
attributes 'Start-Class': "com.abc.abcCompany.service.authserver.AuthServerApplication"
attributes 'Implementation-Version': "001"
}
springBoot {
mainClassName = "com.abcCompany.service.authserver.AuthServerApplication"
}
from(sourceSets.main.output) {
}
}
// During migration changed from BootRepackage to BootJar
task eurekaBoot(type: BootJar, dependsOn: eurekaAppJar) {
mainClassName = 'com.abc.abcCompany.service.eurekaApp.EurekaApplication'
// During migration commented the below code
// customConfiguration = "eurekaconfiguration"
// withJarTask = eztrackerEurekaJar
}
// During migration changed from BootRepackage to BootJar
task oAuthConfigJarBoot(type: BootJar, dependsOn: oAuthConfigJar) {
println " Executing eztrackerApiGatewayBoot task"
mainClassName = 'com.abc.abcCompany.service.authserver.AuthServerApplication'
// During migration commented the below code
// customConfiguration = "zuulconfiguration"
// withJarTask = eztrackerApiGatewayJar
}
bootJar.dependsOn = [eurekaBoot, oAuthConfigJarBoot]
bootJar.enabled = false
In the above code after executing either gradle assemble, It has created two executable jar files eurekaJar-0.0.1.jar, oAuthConfigJar-0.0.1.jar.
Here is my question:
Before the spring boot migration, in the above jars the folder structure is as below:
eurekaJar-0.0.1.jar
-- org
-- META-INF
-- BOOT-INT
-- lib
-- dependencies (jars)
-- classes
-- applicationclasses
after the migration below is the folder structure
eurekaJar-0.0.1.jar -- org -- META-INF -- applicationclasses
so after the migration there is no BOOT-INF folder and dependencies(lib folder)
Because of the above issue my executable jar is not running.
Any comment is appreciated.
Rather than using
from, which will add files directly to the jar, you should configure the classpath of theBootJartasks. Jar files on the classpath will be packaged inBOOT-INF/liband directories will be packaged inBOOT-INF/classes.For reference, you can see how Spring Boot configures the classpath of the default
bootJartask in its own plugin here. From what you’ve shown above, you probably want to use the runtime classpath of the main source set too.Here's a complete example for your
eurekaAppJar:This jar can then be built with the following command:
Its classes and dependencies are packaged in
BOOT-INF/classesandBOOT-INF/librespectively: