Last active
August 29, 2015 14:19
-
-
Save menny/adeaa10544e911c55365 to your computer and use it in GitHub Desktop.
VersionBuilder for 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
android { | |
defaultConfig { | |
versionCode versionbuilder.VersionBuilder.buildGitVersionNumber() | |
versionName versionbuilder.VersionBuilder.buildGitVersionName() | |
} |
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
package versionbuilder | |
class VersionBuilder { | |
static final int GIT_COMMIT_COUNT_NORMALIZE = 230; | |
static final int GIT_COMMIT_COUNT_MINOR_NORMALIZE = 0; | |
static def buildGitVersionNumber() { | |
return Integer.parseInt('git rev-list --count HEAD'.execute().text.trim()) - GIT_COMMIT_COUNT_NORMALIZE; | |
} | |
static def buildGitVersionName() { | |
return String.format("%d.%d.%d-beta", 0, 1, buildGitVersionNumber() - GIT_COMMIT_COUNT_MINOR_NORMALIZE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment