Created
May 3, 2019 13:13
-
-
Save policante/5ad767fbedfe9046a01acf24e4329a96 to your computer and use it in GitHub Desktop.
Script para incrementar versão Android
This file contains 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
def readVersion() { | |
def versionFile = new File(project.rootDir, 'version.properties') | |
def version = new Properties() | |
def stream | |
try { | |
stream = new FileInputStream(versionFile) | |
version.load(stream) | |
} catch (FileNotFoundException ignore) { | |
// | |
} finally { | |
if (stream != null) { | |
stream.close() | |
} | |
} | |
if (!version['major']) version['major'] = "0" | |
if (!version['minor']) version['minor'] = "0" | |
if (!version['build']) version['build'] = "1" | |
return version | |
} | |
def readVersionName() { | |
def version = readVersion() | |
return "1.${version['major']}.${version['minor']}" | |
} | |
def readBuildCode() { | |
def version = readVersion() | |
def build = version['build'] as Integer | |
return build | |
} | |
def incrementBuildNumber(def currentBuild = -1) { | |
def versionFile = new File(project.rootDir, 'version.properties') | |
def version = readVersion() | |
def build = version['build'] as Integer | |
if(currentBuild>0){ | |
build = currentBuild | |
} | |
build++ | |
version['build'] = build.toString() | |
def stream = new FileOutputStream(versionFile) | |
try { | |
version.store(stream, null) | |
} finally { | |
stream.close() | |
} | |
println "Build number is now... " + build | |
return build | |
} | |
def incrementVersionNumber(def type = "minor") { | |
def versionFile = new File(project.rootDir, 'version.properties') | |
def version = readVersion() | |
def major = version['major'] as Integer | |
def minor = version['minor'] as Integer | |
if (type == 'major') { | |
major++ | |
minor = 0 | |
} else if (type == 'minor') { | |
minor++ | |
} | |
version['major'] = major.toString() | |
version['minor'] = minor.toString() | |
def stream = new FileOutputStream(versionFile) | |
try { | |
version.store(stream, null) | |
} finally { | |
stream.close() | |
} | |
println "Version is now... " + major + "." + minor | |
return major + "." + minor | |
} | |
task clean(type: Delete) { | |
delete rootProject.buildDir | |
} | |
task doMajorVersionIncrement() { | |
println "Incrementing major version..." | |
incrementVersionNumber('major') | |
} | |
task doMinorVersionIncrement() { | |
println "Incrementing minor version..." | |
incrementVersionNumber('minor') | |
} | |
task doBuildNumberIncrement() { | |
println "Incrementing build number ${findProperty("build") as Integer}..." | |
incrementBuildNumber(findProperty("build") as Integer) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment