Spring Boot 2 - Change Jar Name

后端 未结 8 1757
耶瑟儿~
耶瑟儿~ 2021-02-06 23:29

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

相关标签:
8条回答
  • 2021-02-07 00:06

    Thanks to @AndyWilkinson for the answer!

    bootJar {
      baseName "jarName"
      launchScript()
    }
    

    .

    springBoot {
      buildInfo {
        properties {
          group = "groupName"
          name = "projectName"
          version = "1.0"
        }
      }
    }
    
    0 讨论(0)
  • 2021-02-07 00:09

    For me worked

    project(':org.awseome.subproject') {
     jar() {
         archiveFileName = 'nameOfJar.jar'
     }
    }
    

    inside of main build.gradle. Used

    Gradle 6.X Spring Boot 2.X

    0 讨论(0)
  • 2021-02-07 00:13

    You can also use:

    tasks.bootJar {
        archiveFileName.set("app.jar")
    }
    

    Or with the jar-plugin

    tasks.jar {
        archiveFileName.set("app.jar")
    }
    
    0 讨论(0)
  • 2021-02-07 00:14

    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.

    0 讨论(0)
  • 2021-02-07 00:15

    Since bootJar tasks extends Jar you can use archiveName to set name the directly:

    bootJar {
       archiveName = 'whatever'
    }
    

    Have a look here.

    0 讨论(0)
  • 2021-02-07 00:31

    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

    0 讨论(0)
提交回复
热议问题