aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-01-18 16:10:28 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-01-18 16:10:28 +0100
commit18be2c5863db6bd179766d1085d71bb94117a4ed (patch)
treef861272b1bc7f6c863315d6d891299954865f964
parent7e3105adc3a32132d3adbcde0bc46808a6de34e9 (diff)
downloadio.trygvis.soilmoisture-android-18be2c5863db6bd179766d1085d71bb94117a4ed.tar.gz
io.trygvis.soilmoisture-android-18be2c5863db6bd179766d1085d71bb94117a4ed.tar.bz2
io.trygvis.soilmoisture-android-18be2c5863db6bd179766d1085d71bb94117a4ed.tar.xz
io.trygvis.soilmoisture-android-18be2c5863db6bd179766d1085d71bb94117a4ed.zip
Trying to automatically generate versions numbers from Git.
-rw-r--r--app/build.gradle36
1 files changed, 34 insertions, 2 deletions
diff --git a/app/build.gradle b/app/build.gradle
index cb80b6c..2732c04 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,3 +1,31 @@
+def getVersionCode = { ->
+ try {
+ def stdout = new ByteArrayOutputStream()
+ exec {
+ commandLine 'git', 'rev-list', '--first-parent', '--count', 'master'
+ standardOutput = stdout
+ }
+ return Integer.parseInt(stdout.toString().trim())
+ }
+ catch (ignored) {
+ return -1;
+ }
+}
+
+def getVersionName = { ->
+ try {
+ def stdout = new ByteArrayOutputStream()
+ exec {
+ commandLine 'git', 'describe', '--tags', '--dirty'
+ standardOutput = stdout
+ }
+ return stdout.toString().trim()
+ }
+ catch (ignored) {
+ return null;
+ }
+}
+
buildscript {
repositories {
mavenCentral()
@@ -25,8 +53,10 @@ android {
applicationId 'io.trygvis.soilmoisture'
minSdkVersion 19
targetSdkVersion 19
- versionCode 1
- versionName "1.0"
+ versionCode getVersionCode()
+ versionName getVersionName()
+
+ println("versionCode=$versionCode, versionName=$versionName")
}
buildTypes {
release {
@@ -39,6 +69,8 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}
lintOptions {
+ // The linter errors out with an NPE.
+ checkReleaseBuilds false
abortOnError false
}
productFlavors {