From 18be2c5863db6bd179766d1085d71bb94117a4ed Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 18 Jan 2015 16:10:28 +0100 Subject: Trying to automatically generate versions numbers from Git. --- app/build.gradle | 36 ++++++++++++++++++++++++++++++++++-- 1 file 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 { -- cgit v1.2.3