Last active
March 8, 2016 10:59
-
-
Save burmudar/968477e1608c62362742 to your computer and use it in GitHub Desktop.
Gradle task to add build information to build resources output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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