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 G
Thanks to @AndyWilkinson for the answer!
bootJar {
baseName "jarName"
launchScript()
}
.
springBoot {
buildInfo {
properties {
group = "groupName"
name = "projectName"
version = "1.0"
}
}
}
For me worked
project(':org.awseome.subproject') {
jar() {
archiveFileName = 'nameOfJar.jar'
}
}
inside of main build.gradle. Used
Gradle 6.X Spring Boot 2.X
You can also use:
tasks.bootJar {
archiveFileName.set("app.jar")
}
Or with the jar-plugin
tasks.jar {
archiveFileName.set("app.jar")
}
My goal was to remove version from the archive name. I did it this way:
bootJar {
archiveName = "$baseName.$extension"
}
Now Gradle generates "project-name.jar" instead of "project-name-1.0-SNAPSHOT.jar". This solution is general and doesn't hardcode any particular archive name.
Since bootJar tasks extends Jar
you can use archiveName
to set name the directly:
bootJar {
archiveName = 'whatever'
}
Have a look here.
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