Skip to content

Instantly share code, notes, and snippets.

@aaiezza
Last active April 20, 2020 13:06
Show Gist options
  • Save aaiezza/5cd8e43430f8e93049d424dafa3ebdaa to your computer and use it in GitHub Desktop.
Save aaiezza/5cd8e43430f8e93049d424dafa3ebdaa to your computer and use it in GitHub Desktop.
Maven Project | Bump Major, Minor, or Patch Sematic Version
currentversion() {
# If xpath is on your machine (macos will I believe),
# and the project's version is in the path `project.version`,
# then it is nice to use this because it is faster.
# xpath ./pom.xml 'project/version/text()' 2>/dev/null
# Otherwise:
mvn help:evaluate -Dexpression=project.version -q -DforceStdout
}
bumpmajor() {
CURRENT_VERSION=`currentversion`
[[ $CURRENT_VERSION == *"-"* ]] && VERSION_SUFFIX="-${CURRENT_VERSION##*-}"
OLD_MAJOR_VERSION=$((`echo $CURRENT_VERSION | grep -Po '^[0-9]+(?=\.)'`))
NEW_MAJOR_VERSION=$((OLD_MAJOR_VERSION + 1)) # bump!
NEW_FULL_VERSION=$(echo $CURRENT_VERSION | sed "s/^[0-9]*.*/$NEW_MAJOR_VERSION.0.0/g")$VERSION_SUFFIX
setversion "$NEW_FULL_VERSION"
mvn versions:commit # Deletes the backup pom used by the 'revert' command
update_pom-dependency_file
}
bumpminor() {
CURRENT_VERSION=`currentversion`
[[ $CURRENT_VERSION == *"-"* ]] && VERSION_SUFFIX="-${CURRENT_VERSION##*-}"
OLD_MINOR_VERSION=$((`echo $CURRENT_VERSION | grep -Po '(?<=\.)[0-9]+(?=\.)'`))
NEW_MINOR_VERSION=$((OLD_MINOR_VERSION + 1)) # bump!
NEW_FULL_VERSION=$(echo $CURRENT_VERSION | sed "s/\.[0-9]*.*/.$NEW_MINOR_VERSION.0/g")$VERSION_SUFFIX
setversion "$NEW_FULL_VERSION"
mvn versions:commit # Deletes the backup pom used by the 'revert' command
update_pom-dependency_file
}
bumppatch() {
CURRENT_VERSION=`currentversion`
[[ $CURRENT_VERSION == *"-"* ]] && VERSION_SUFFIX="-${CURRENT_VERSION##*-}"
OLD_PATCH_VERSION=$((`echo $CURRENT_VERSION | grep -Po '(?<=\.)[0-9]+'$VERSION_SUFFIX'$'`))
NEW_PATCH_VERSION=$((OLD_PATCH_VERSION + 1)) # bump!
NEW_FULL_VERSION=$(echo $CURRENT_VERSION | sed "s/\.[0-9]*"$VERSION_SUFFIX"$/.$NEW_PATCH_VERSION/g")$VERSION_SUFFIX
setversion "$NEW_FULL_VERSION"
mvn versions:commit # Deletes the backup pom used by the 'revert' command
update_pom-dependency_file
}
bumpmajor() {
CURRENT_VERSION=`currentversion`
[[ $CURRENT_VERSION == *"-"* ]] && VERSION_SUFFIX="-${CURRENT_VERSION##*-}"
OLD_MAJOR_VERSION=$((`echo $CURRENT_VERSION | grep -Po '^[0-9]+(?=\.)'`))
NEW_MAJOR_VERSION=$((OLD_MAJOR_VERSION + 1)) # bump!
NEW_FULL_VERSION=$(echo $CURRENT_VERSION | sed "s/^[0-9]*.*/$NEW_MAJOR_VERSION.0.0/g")$VERSION_SUFFIX
setversion "$NEW_FULL_VERSION"
mvn versions:commit # Deletes the backup pom used by the 'revert' command
update_pom-dependency_file
}
bumpminor() {
CURRENT_VERSION=`currentversion`
[[ $CURRENT_VERSION == *"-"* ]] && VERSION_SUFFIX="-${CURRENT_VERSION##*-}"
OLD_MINOR_VERSION=$((`echo $CURRENT_VERSION | grep -Po '(?<=\.)[0-9]+(?=\.)'`))
NEW_MINOR_VERSION=$((OLD_MINOR_VERSION + 1)) # bump!
NEW_FULL_VERSION=$(echo $CURRENT_VERSION | sed "s/\.[0-9]*.*/.$NEW_MINOR_VERSION.0/g")$VERSION_SUFFIX
setversion "$NEW_FULL_VERSION"
mvn versions:commit # Deletes the backup pom used by the 'revert' command
update_pom-dependency_file
}
bumppatch() {
CURRENT_VERSION=`currentversion`
[[ $CURRENT_VERSION == *"-"* ]] && VERSION_SUFFIX="-${CURRENT_VERSION##*-}"
OLD_PATCH_VERSION=$((`echo $CURRENT_VERSION | grep -Po '(?<=\.)[0-9]+'$VERSION_SUFFIX'$'`))
NEW_PATCH_VERSION=$((OLD_PATCH_VERSION + 1)) # bump!
NEW_FULL_VERSION=$(echo $CURRENT_VERSION | sed "s/\.[0-9]*"$VERSION_SUFFIX"$/.$NEW_PATCH_VERSION/g")$VERSION_SUFFIX
setversion "$NEW_FULL_VERSION"
mvn versions:commit # Deletes the backup pom used by the 'revert' command
update_pom-dependency_file
}
currentversion() {
# If xpath is on your machine (macos will I believe),
# and the project's version is in the path `project.version`,
# then it is nice to use this because it is faster.
# xpath ./pom.xml 'project/version/text()' 2>/dev/null
# Otherwise:
mvn help:evaluate -Dexpression=project.version -q -DforceStdout
}
setversion() {
mvn versions:set -DnewVersion="$1"
}
update_pom-dependency_file() {
mvn clean verify -Dmaven.test.skip=true
}
setversion() {
mvn versions:set -DnewVersion="$1"
}
update_pom-dependency_file() {
mvn clean verify -Dmaven.test.skip=true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment