[Java] Add time stamp to JAR file name with Gradle

less than 1 minute read


  • Add time stamp to file name when creating JAR file with Gradle
  • Operating environment: Gradle 6.6 + Groovy 2.5.12


Add date and time character string to project.version in build.gradle file.

plugins {

project.version = '1.2.3' +'_' + getTimestamp()

def getTimestamp() {
  // year month date _ hour minute second _ millisecond
  return new Date().format('yyyyMMdd_HHmmss_SSS')

Create a JAR file with the jar task or build task.

$ gradle build

You can see that jar is created in build/libs with the following file name.

$ ls build/libs

Reference materials