5

There three launcher in Spring Boot: JarLauncher/PropertiesLauncher/WarLauncher. For executable jar, JarLauncher will be used by default. Now I want to use PropertiesLauncher instead so that I could use external classpath. How could I specify that is spring boot gradle plugin?

Accoring to D3.1 of this doc D.3.1 Launcher manifest, I can specify the main class in MANIFEST.MF like this:

Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.mycompany.project.MyApplication

However, in Spring Boot Gradle, the following code snippet actually specifies the Start-Class, not the Main-Class:

springBoot {
    mainClass = "com.sybercare.HealthServiceApplication"
}

Do I need to create the MANIFIEST.MF manually or there is a better way to do this?

Thanks!

xing
  • 464
  • 9
  • 17

3 Answers3

7

Add the layout property:

springBoot{
    mainClass = "com.sybercare.HealthServiceApplication"
    layout = "ZIP"
}

layout = ZIP Triggers SpringBoot to use the PropertiesLauncher

pczeus
  • 7,709
  • 4
  • 36
  • 51
  • thank you so much @pczeus. I was looking for this solution but could not find it easily. where did you find docs for that? – FranXho Mar 13 '18 at 11:20
1

The layout property defaults to a guess based on the archive type (jar or war). For the PropertiesLauncher the layout is ZIP (even though the output might be a jar file).

https://docs.spring.io/autorepo/docs/spring-boot/1.2.0.M2/maven-plugin/usage.html

shixu
  • 11
  • 3
0

The other answers are outdated now. The current answer seems to be:

tasks.getByName<BootJar>("bootJar") {
    manifest {
        attributes("Main-Class" to "org.springframework.boot.loader.PropertiesLauncher")
    }
}

as per https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#packaging-executable.configuring.properties-launcher

sumek
  • 26,495
  • 13
  • 56
  • 75