Create a gist now

Instantly share code, notes, and snippets.

VersionBuilder for Gradle
android {
defaultConfig {
versionCode versionbuilder.VersionBuilder.buildGitVersionNumber()
versionName versionbuilder.VersionBuilder.buildGitVersionName()
}
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