I do differently. The idea is based on the use of the version number from the VCS.
In the case of git, do this:
//извлечение порядкового номера версии стартуя от HEAD def getVersionCode = { -> try { def stdout = new ByteArrayOutputStream() exec { standardOutput = stdout commandLine 'git', 'rev-list', '--first-parent', '--count', 'master' } println("Build #"+stdout) return asInteger(stdout.toString("ASCII").trim()) } catch (Exception e) { e.printStackTrace(); return 0; } } //присваиваем версию def char[] patches='abcdefghijklmnopqrstuwxyz'.toCharArray() def patch=1 //иногда бывает нужно определить патч внутри версии def majorVersion=1 def minorVersion=0 def revision=getVersionCode() defaultConfig { //blah-blah versionName = majorVersion + '.' + minorVersion + '.' + revision + patches[patch] versionCode = 10000000*majorVersion+10000*minorVersion + 10*revision+patch }
At the output we get something like:
versionName="1.0.25a" versionCode="10000251"
Similar scripts can be written for SVN
Update
The incrementing of the version will be at every commit . Separately, you can also write githash in order to restore which version dropped and where by logs. When there are a lot of users, not all upgrade versions in time - an extremely useful thing, I tell you. Several times really rescued.