Skip to content

Instantly share code, notes, and snippets.

@burmudar
Last active March 8, 2016 10:59
Show Gist options
  • Save burmudar/968477e1608c62362742 to your computer and use it in GitHub Desktop.
Save burmudar/968477e1608c62362742 to your computer and use it in GitHub Desktop.
Gradle task to add build information to build resources output
import java.time.LocalDateTime
apply plugin: 'application'
apply plugin: 'java'
task buildVersion {
//replacing " characters othewise they're included in the property value when read from the Properties class
def version = 'hg parents --template "{latesttag}.{latesttagdistance}-{node|short}"'.execute().text.trim().replace("\"", "")
def destDir = sourceSets.main.output.resourcesDir
destDir.mkdirs()
def buildFile = new File(destDir, "build.properties")
buildFile.createNewFile()
buildFile.text = "version=${version}\ndate=${LocalDateTime.now()}\n"
}
processResources.mustRunAfter buildVersion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment