apply from: 'functions.gradle'
...
buildConfigField 'String', 'GIT_HASH', "\"${gitHash()}\""
buildConfigField 'String', 'BUILD_TIME', "\"${buildTime()}\""
import java.text.SimpleDateFormat
ext.buildTime = { ->
def df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'")
df.setTimeZone(TimeZone.getTimeZone("UTC"))
return df.format(new Date())
}
ext.gitHash = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}