Skip to content

Instantly share code, notes, and snippets.

@alivcor
Created October 30, 2020 22:40
Show Gist options
  • Save alivcor/ca41d28bfaba2dbea38a682ac2342a38 to your computer and use it in GitHub Desktop.
Save alivcor/ca41d28bfaba2dbea38a682ac2342a38 to your computer and use it in GitHub Desktop.
VersioningGroovy
class GroovyIncrementalVersioning {
/*
* Created by @alivcor (Abhinandan Dubey) on 10/26/20
* Licensed under the Mozilla Public License Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
static String getNextReleaseVersion(String version) {
String[] versionNumber;
versionNumber = version.split('-')[0].split(/\./);
Integer majorVersion = versionNumber[0] as Integer;
Integer minorVersion = versionNumber[1] as Integer;
String newVersion = "";
if(minorVersion > 9){
minorVersion = 0;
majorVersion = majorVersion + 1;
} else {
minorVersion = minorVersion + 1;
}
return majorVersion.toString() + "." + minorVersion.toString();
}
static String getNextSnapshotVersion(String version) {
return getNextReleaseVersion(version) + "-SNAPSHOT";
}
static String getCurrentReleaseVersion(String version) {
return version.replaceAll("-SNAPSHOT", "");
}
static void main(String[] args) {
String version = "1.6-SNAPSHOT";
println(getCurrentReleaseVersion(version));
println(getNextSnapshotVersion(version));
println(getNextReleaseVersion(version));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment