S_K
S_K

Reputation: 772

Create jar with fix name excluding version using gradle

I want to create a fat jar using gradle only with name, not include a version of the project.

I am using gradle 5.1 and spring boot 2.1.1.

I have tried the following solutions with no luck

  1. https://stackoverflow.com/a/53123771/8123983
  2. https://stackoverflow.com/a/31407245/8123983

    • Default jar name project-0.0.1-SNAPSHOT.jar

    • Expected jar name project-xyz.jar

Upvotes: 6

Views: 4227

Answers (2)

Vladyslav Kolesov
Vladyslav Kolesov

Reputation: 133

On an example of Spring Boot 2.4+ && Gradle 6+, modify build.gradle:

plugins {
    id 'org.springframework.boot' version '2.4.0.RELEASE'
}

bootJar {
    archiveFileName = 'flawless-application.jar'
}

without boot plugin

jar {
    archiveFileName = 'flawless-application.jar'
}

More docs here:

  1. https://docs.gradle.org/current/dsl/org.gradle.api.Project.html
  2. https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.Jar.html#org.gradle.api.tasks.bundling.Jar:archiveFileName
  3. https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#packaging-executable

Upvotes: 2

S_K
S_K

Reputation: 772

I found the solution, finally!

jar { archivesBaseName="project-name" project.version="" }

I have also tried with version instead of project.version. But, it's not working anymore in gradle 5.1 as it is deprecated as per the documentation.

https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.Jar.html#org.gradle.api.tasks.bundling.Jar:version

archivesBaseName changes only the prefix name, not remove the version from the jar name.

Upvotes: 10

Related Questions