我在Gradle项目中使用Spring Boot 2在Jenkins中进行jar的构建,我想更改该jar文件的名称。

默认情况下,Spring Boot 2使用Gradle属性rootProject.name,可以在/settings.gradle文件中设置它。

但是,我想更改jar文件名,而不更改rootProject.name

这是bootJar文件的springBootbuild.gradle部分:

bootJar {
  launchScript()
}


springBoot {
  buildInfo {
    properties {
      artifact = "jarName"
      group = "groupName"
      name = "projectName"
      version = "1.0"
    }
  }
}

注意:读了https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/html/#integrating-with-actuator后, artifact没有像我期望的那样设置jar名称。

最佳答案

archiveFileName是新的热点。其他所有东西都已弃用。

bootJar {
   archiveFileName = "${archiveBaseName.get()}.${archiveExtension.get()}"
}

或等效的Kotlin DSL:
tasks.getByName<org.springframework.boot.gradle.tasks.bundling.BootJar>("bootJar") {
   this.archiveFileName.set("${archiveBaseName.get()}.${archiveExtension.get()}")
}

看到:
  • 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
  • 关于spring-boot - Spring Boot 2-更改Jar名称,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53123012/

    10-11 09:13
    查看更多