I am using Spring Boot 2 in my Gradle project to do a build to jar in Jenkins, and I would like to change the name of that jar file.
By default, Spring Boot 2 used the Gradle property rootProject.name
, which can be set in the /settings.gradle
file.
However, I would like to change the jar file name, without changing the rootProject.name
.
Here are my bootJar
and springBoot
sections of the build.gradle
file:
bootJar { launchScript() }
.
springBoot { buildInfo { properties { artifact = "jarName" group = "groupName" name = "projectName" version = "1.0" } } }
Note: artifact
is not setting the jar name, as I expected it to, after reading: https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/html/#integrating-with-actuator
If you want to rename the JAR, source JAR and javadoc JAR with a single setting, while still including the classifier and version, set archiveBaseName at the top level. This is how it's listed in the gradle docs.
bootJar on the other hand is a specific task added by Spring Boot Gradle plugin that, when the java plugin is present, attaches itself to the assemble lifecycle task. The assemble task is automatically configured to depend upon the bootJar task so running assemble (or build ) will also run the bootJar task.
Spring Boot's “JarFile” Class. The core class used to support loading nested jars is org.springframework.boot.loader.jar.JarFile . It lets you load jar content from a standard jar file or from nested child jar data.
archiveFileName
is the new hotness. Everything else is deprecated.
bootJar { archiveFileName = "${archiveBaseName.get()}.${archiveExtension.get()}" }
or the Kotlin DSL equivalent:
tasks.getByName<org.springframework.boot.gradle.tasks.bundling.BootJar>("bootJar") { this.archiveFileName.set("${archiveBaseName.get()}.${archiveExtension.get()}") }
See:
https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.Jar.html#org.gradle.api.tasks.bundling.Jar:archiveName
https://docs.gradle.org/current/userguide/lazy_configuration.html
Since bootJar
tasks extends Jar
you can use archiveName
to set name the directly:
bootJar { archiveName = 'whatever' }
Have a look here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With