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!
Add the layout property:
springBoot{
mainClass = "com.sybercare.HealthServiceApplication"
layout = "ZIP"
}
layout = ZIP Triggers SpringBoot to use the PropertiesLauncher
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
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
Related
I would like to set the application name in Spring Boot to the value from rootProject.name. Is there a way to do that?
Spring Boot reads the application name from the configuration property spring.application.name. Gradle can generate a configuration file containing that property.
Put in the src/main/resources/application.properties file:
spring.application.name=${rootProject.name}
Add the Gradle task:
processResources {
filesMatching("application.properties") {
expand project.properties
}
}
I am using karate 0.9.2 with gradle. My project requires to have all karate tests inside src/main/java. So I configured the gradle dependency as ‘compile’ instead of ‘testCompile’ and also modified the sourceSets to point to main instead of test. When I ran my runner class with above configuration I got empty test suite message.
build.gradle snippet:
compile 'com.intuit.karate:karate-junit4:0.9.3'
compile 'com.intuit.karate:karate-apache:0.9.3'
sourceSets {
test {
resources {
srcDir file('src/main/java')
exclude '**/*.java'
}
}
}
Additionally, I have is to run the karate tests from the deployable project jar. Please point me the resources I can refer to achieve the same.
Not something we directly support but teams have done this in Spring Boot etc. It should be possible, see if this thread helps: https://github.com/intuit/karate/issues/520
Also you may not need JUnit also: https://github.com/intuit/karate/issues/427
And see the sample project in this ticket as an example: https://github.com/intuit/karate/issues/529
EDIT - in 1.0 onwards we hope that class-loading from spring-boot JAR files is more reliable: https://github.com/intuit/karate/issues/751
From command line, I need to build an executable jar without dependencies.
The current "gradle build" command gives me a jar with dependencies.
Couldn't find this on StackOverflow. If it's a duplicate question, point me there. Thanks.
As you have SpringBoot plugin enabled, the default behavior is to build an executable jar (fat-jar) containing all dependencies, through thebootJar task.
You can still generate a single "standard" jar if you need, this is explained in the documentation : Spring Boot Gradle plugin
jar {
enabled = true
}
bootJar {
classifier = 'boot'
}
Our application is using EclipseLink. For production artifacts we use static weaving, we have a Gradle task that builds a separate jar that should be included in the Spring Boot fat jar. During development we are not using weaving so we don't have this artifact.
What we would like to do is customize the classpath in the bootJar task so that we include the weaved artifact and exclude the source of the un-weaved module. Prior to 2.0.x of the Spring Boot Gradle plugin this was achieved by specifying a customConfiguration in a task of type bootRepackage, like this:
task singleJar(type: BootRepackage) {
customConfiguration = "weavedRuntime"
}
But this option seems to be missing in the 2.0.x version. Is there any way of overriding the configuration in the new version?
Alternatively we need to modify the classpath, but just for the bootJar task. The normal runtime classpath shoukd include the un-weaved module, but the bootJar classpath should include the weaved artifact and exclude the un-weaved module. Any suggestions on how to do this?
I'm trying to launch another main method in another (test) jar.
According to this entry,I added
task packageTests(type: Jar) {
from sourceSets.test.output
}
to build.gradle to package all test resources and classes into a jar.
Then I executed
gradle bootRepackage which creates MyWS-0.0.1-SNAPSHOT.jar and
gradle packageTests which creates MyWS.jar.
Thereafter I copied both jars in a folder and created an application.properties with
loader.path=lib:/*,MyWS.jar
loader.main=db.DBTest
After reading the boot manual appendix, I try to launch the other main (in MyWS.jar/db.DBTest) with
java -cp ./MyWS-0.0.1-SNAPSHOT.jar;./MyWS.jar org.springframework.boot.loader.PropertiesLauncher -Dloader.main=db.DBTest
but the 'old' Start-Class of MyWS-0.0.1-SNAPSHOTs MANIFEST is still launched.
Any ideas how to solve this?