The example you're referring to is almost correct. With a couple of minor tweaks it works as expected:
import java.text.SimpleDateFormat
import org.ajoberstar.grgit.Grgit
plugins {
id "org.ajoberstar.grgit" version "1.7.2"
}
version = 1.0
task versionTxt() {
doLast {
new File(projectDir, "version.txt").text = """
Version: $version
Revision: ${grgit.head().abbreviatedId}
Buildtime: ${new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date())}
Application-name: foobarbaz app
"""
}
}
Run gradle versionTxt
to get the desired output.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…