Created
April 22, 2016 03:37
-
-
Save kiwiandroiddev/6083e33945744cf4f69473bb16e9517c to your computer and use it in GitHub Desktop.
Git interface functions for gradle build scripts (e.g. for Android). To use add this to your build script: apply from: 'git.gradle'
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
| def getGitCommit() { | |
| return 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim() | |
| } | |
| def getGitTag() { | |
| def p = Runtime.getRuntime().exec("git describe HEAD --abbrev=0") | |
| if (p.waitFor() != 0) { | |
| return "none" // no tag | |
| } | |
| return p.getInputStream().readLines().get(0).toString().trim() | |
| } | |
| def getGitBranchCommitNumber() { | |
| def p = Runtime.getRuntime().exec("git rev-list HEAD --count") | |
| if (p.waitFor() != 0) { | |
| return 0 // no git revisions | |
| } | |
| return p.getInputStream().readLines().get(0).toInteger() | |
| } | |
| // Export functions by turning them into closures | |
| ext { | |
| getGitTag = this.&getGitTag | |
| getGitCommit = this.&getGitCommit | |
| getGitBranchCommitNumber = this.&getGitBranchCommitNumber | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment