0

How to append a timestamp to jar in the spring boot Gradle project?

./gradlew build

Creates jar app-0.0.1-SNAPSHOT.jar, how to create jar with timestamp

app-0.0.1-SNAPSHOT-2020-11-09.02-30.jar

-------- Gradle

plugins {
    id 'org.springframework.boot' version '2.3.5.RELEASE'
    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
    id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

test {
    useJUnitPlatform()
}
Thirumal
  • 8,280
  • 11
  • 53
  • 103

1 Answers1

3

How about

bootJar {
    archiveFileName = "app-0.0.1-SNAPSHOT-"+new Date().format('yyyy-MM-dd.HH-mm')+ ".jar"
}

Tested with gradle 6.6.1 and spring boot plugin version 2.3.4

Shawrup
  • 2,478
  • 2
  • 12
  • 21