Last active
April 20, 2020 13:06
-
-
Save aaiezza/5cd8e43430f8e93049d424dafa3ebdaa to your computer and use it in GitHub Desktop.
Maven Project | Bump Major, Minor, or Patch Sematic Version
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
| 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 | |
| } |
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
| 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 | |
| } |
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
| 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 | |
| } |
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
| 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 | |
| } |
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
| 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 | |
| } |
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
| setversion() { | |
| mvn versions:set -DnewVersion="$1" | |
| } |
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
| 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