Last active
November 24, 2018 12:01
-
-
Save era5mx/ad8fcac5585fdd90d8ee43659648276a to your computer and use it in GitHub Desktop.
Automatic versioning jar with gradle build tool. Place the code snippet of the automatic-versioning.gradle file in your build.gradle file. Valid values for UpgradeVersion are: Major, Minor, Patch or None.
This file contains hidden or 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
compileJava{ | |
doFirst { | |
def propertyFile = file "/version.properties" | |
def props = new Properties() | |
propertyFile.withReader { props.load(it) } | |
print "Actual Version: " | |
version = props.getProperty('MajorVersion') + '.' + props.getProperty('MinorVersion') + '.' + props.getProperty('PatchVersion') + '-' + props.getProperty('LabelVersion') + '(' + props.getProperty('BuildVersion') + props.getProperty('MajorVersion') + props.getProperty('MinorVersion') + props.getProperty('PatchVersion') + ")" | |
println("version = ${version}") | |
} | |
doLast { | |
def propertyFile = file "/version.properties" | |
def props = new Properties() | |
propertyFile.withReader { props.load(it) } | |
print "Upgrade Version: " | |
println props.getProperty('UpgradeVersion') + "Version" | |
if(props.getProperty('UpgradeVersion')!="None") { | |
props.setProperty(props.getProperty('UpgradeVersion') + "Version", Integer.toString(Integer.parseInt(props.getProperty(props.getProperty('UpgradeVersion') + "Version"))+1)) | |
} | |
props.setProperty("BuildVersion", Calendar.getInstance().get(Calendar.MONTH)+1 + "" + Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + "" + Calendar.getInstance().get(Calendar.HOUR_OF_DAY)) | |
propertyFile.withWriter { props.store(it, null) } | |
print "Next Version: version = " | |
propertyFile.withReader { props.load(it) } | |
println props.getProperty('MajorVersion') + '.' + props.getProperty('MinorVersion') + '.' + props.getProperty('PatchVersion') + '-' + props.getProperty('LabelVersion') + '(' + props.getProperty('BuildVersion') + props.getProperty('MajorVersion') + props.getProperty('MinorVersion') + props.getProperty('PatchVersion') + ")" | |
} | |
} |
This file contains hidden or 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
LabelVersion=RC | |
MajorVersion=1 | |
PatchVersion=1 | |
UpgradeVersion=Patch | |
BuildVersion=1123 | |
MinorVersion=5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment