Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Npm version for gradle
def getVersionName = { getVersionProps()['sandboxVersionName'] }
def getVersionProps() {
def versionPropsFile = file('gradle.properties')
if (!versionPropsFile.exists()) {
versionPropsFile.createNewFile()
}
def versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
return versionProps
}
def getVersionNamePatch = { (getVersionName() =~ /\d+/)[2].toInteger() }
def getVersionNameMinor = { (getVersionName() =~ /\d+/)[1].toInteger() }
def getVersionNameMajor = { (getVersionName() =~ /\d+/)[0].toInteger() }
private def getAppVersionCode() { getVersionProps()['sandboxVersionCode'].toInteger() }
private void save(major, minor, patch, versionCode) {
save("${major}.${minor}.${patch}".toString(), versionCode.toString())
}
private void save(versionName, versionCode) {
def versionProps = getVersionProps()
versionProps['sandboxVersionName'] = versionName
versionProps['sandboxVersionCode'] = versionCode
versionProps.store(file('gradle.properties').newWriter(), null)
}
task bumperInit() {
group = 'bumper'
doLast {
def versionName = project.hasProperty('bumperVersionName') ? bumperVersionName : '1.0.0'
def versionCode = project.hasProperty('bumperVersionCode') ? bumperVersionCode : '1'
save(versionName, versionCode)
}
}
task bumperVersionPatch () {
group = 'bumper'
doLast {
save(getVersionNameMajor(), getVersionNameMinor(), getVersionNamePatch() + 1, getAppVersionCode() + 1)
}
}
task bumperVersionMinor () {
group = 'bumper'
doLast {
save(getVersionNameMajor(), getVersionNameMinor() + 1, 0, getAppVersionCode() + 1)
}
}
task bumperVersionMajor () {
group = 'bumper'
doLast {
save(getVersionNameMajor() + 1, 0, 0, getAppVersionCode() + 1)
}
}
def getVersionName = { getVersionProps()['versionName'] }
def getVersionProps() {
def versionPropsFile = file('version.properties')
if (!versionPropsFile.exists()) {
versionPropsFile.createNewFile()
}
def versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
return versionProps
}
def getVersionNamePatch = { (getVersionName() =~ /\d+/)[2].toInteger() }
def getVersionNameMinor = { (getVersionName() =~ /\d+/)[1].toInteger() }
def getVersionNameMajor = { (getVersionName() =~ /\d+/)[0].toInteger() }
private def getAppVersionCode() { getVersionProps()['versionCode'].toInteger() }
private void save(major, minor, patch, versionCode) {
save("${major}.${minor}.${patch}".toString(), versionCode.toString())
}
private void save(versionName, versionCode) {
def versionProps = getVersionProps()
versionProps['versionName'] = versionName
versionProps['versionCode'] = versionCode
versionProps.store(file('version.properties').newWriter(), null)
}
task bumperInit() {
group = 'bumper'
doLast {
def versionName = project.hasProperty('bumperVersionName') ? bumperVersionName : '0.0.1'
def versionCode = project.hasProperty('bumperVersionCode') ? bumperVersionCode : '1'
save(versionName, versionCode)
}
}
task bumperVersionPatch () {
group = 'bumper'
doLast {
save(getVersionNameMajor(), getVersionNameMinor(), getVersionNamePatch() + 1, getAppVersionCode() + 1)
}
}
task bumperVersionMinor () {
group = 'bumper'
doLast {
save(getVersionNameMajor(), getVersionNameMinor() + 1, 0, getAppVersionCode() + 1)
}
}
task bumperVersionMajor () {
group = 'bumper'
doLast {
save(getVersionNameMajor() + 1, 0, 0, getAppVersionCode() + 1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment