How to specify the Launcher in Spring Boot Gradle?
Asked Answered
S

3

6

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!

Suavity answered 23/3, 2016 at 1:34 Comment(0)
E
7

Add the layout property:

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

layout = ZIP Triggers SpringBoot to use the PropertiesLauncher

Ecg answered 24/3, 2016 at 2:33 Comment(1)
thank you so much @pczeus. I was looking for this solution but could not find it easily. where did you find docs for that?Throng
O
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

Oligocene answered 8/7, 2020 at 12:16 Comment(0)
A
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

Afterclap answered 18/2, 2022 at 8:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.