Maven Version Plugin Automatic Updates
Whenever you edit a Java/Kotlin maven project, you should see if you need to update any used libraries.
For this purpose, I have a bash alias command which runs the next three statements in a row:
# do minor updates in pom.xml automatically, but ignore some (beta) versions
mvn versions:update-properties -DallowMajorUpdates=false -Dmaven.version.rules=https://www.kaper.com/mvn/version-rules.html -DgenerateBackupPoms=false
# SHOW major updates (but ignore some (beta) versions) which you could do also (but not applied automatically)
mvn versions:display-property-updates -Dmaven.version.rules=https://www.kaper.com/mvn/version-rules.html -DgenerateBackupPoms=false
# show the minor updates as done in step 1
git diff
Code language: Bash (bash)
The full alias line looks like this (in ~/.bash_aliased)
alias mvn.minorupdates="mvn versions:update-properties -DallowMajorUpdates=false -Dmaven.version.rules=https://www.kaper.com/mvn/version-rules.html -DgenerateBackupPoms=false ; mvn versions:display-property-updates -Dmaven.version.rules=https://www.kaper.com/mvn/version-rules.html -DgenerateBackupPoms=false ; git diff"
Code language: Bash (bash)
Note: it seems the plug-in is not perfect 😉 Sometimes it does major updates, even if you ask it not to. So always carefully look at the changes which are made!
The URL as used in the commands serves this XML config file: version-rules.html
<ruleset comparisonMethod="maven"
xmlns="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0 http://mojo.codehaus.org/versions-maven-plugin/xsd/rule-2.0.0.xsd">
<ignoreVersions>
<!-- taken from https://stackoverflow.com/questions/10230903/maven-versions-plugin-how-to-exclude-alpha-beta-versions-from-response -->
<ignoreVersion type="regex">.*[-_\.](alpha|Alpha|ALPHA|b|beta|Beta|BETA|rc|RC|M|EA)[-_\.]?[0-9]*</ignoreVersion>
<!-- my own additions -->
<ignoreVersion type="regex">.*(alpha|Alpha|ALPHA|beta|Beta|BETA|preview|Preview|PREVIEW).*</ignoreVersion>
</ignoreVersions>
</ruleset>
Code language: HTML, XML (xml)
This contains some regular expressions to skip certain versions. You can copy this file, and tweak where needed, and use it in your commands. Or you can use my version as is.
Here a list of useful run options for the version plugin:
# maven version plugin, allows to show suggested updates, or to do the update automatically.
# See also: https://www.mojohaus.org/versions-maven-plugin/update-properties-mojo.html for more options and settings.
# my recommended option to always use as step (1):
# run this command to UPDATE minor versions, filtering out the mentioned regexes:
mvn versions:update-properties -DallowMajorUpdates=false -Dmaven.version.rules=https://www.kaper.com/mvn/version-rules.html -DgenerateBackupPoms=false
# my recommended option to run as step (2) after step (1):
# run this command to LIST all version updates, filtering out the mentioned regexes:
mvn versions:display-property-updates -Dmaven.version.rules=https://www.kaper.com/mvn/version-rules.html -DgenerateBackupPoms=false
# and many more versions / variations of the check/update calls, take your pick:
# run this command to LIST all possible version updates, not filtering stuff:
mvn versions:display-property-updates -DgenerateBackupPoms=false
# run this command to LIST all possible minor version updates, not filtering stuff:
mvn versions:display-property-updates -DallowMajorUpdates=false -DgenerateBackupPoms=false
# run this command to LIST all minor version updates, filtering out the mentioned regexes:
mvn versions:display-property-updates -DallowMajorUpdates=false -Dmaven.version.rules=https://www.kaper.com/mvn/version-rules.html -DgenerateBackupPoms=false
# run this command to UPDATE ALL versions, filtering out the mentioned regexes:
mvn versions:update-properties -Dmaven.version.rules=https://www.kaper.com/mvn/version-rules.html -DgenerateBackupPoms=false
# run this command to UPDATE ALL versions, not filtering stuff:
mvn versions:update-properties -DgenerateBackupPoms=false
Code language: Bash (bash)