Taming the maven versions plugin - configuring rules

Share on:

I have been a user of the versions maven plugin for many years but I think I never actually used it to its full potential.

Latetly I wanted to control the way updates were resolved when I was invoking

1mvn versions:display-dependency-updates

I wanted to get rid of snapshos and all sorts of different naming convensions libraries use to indicate that this is a work in progress , beta etc.

Fortunately the plugin has a configurable way to define rules that will be evaluated during the execution. These rules support regex-es so you can easily filter out the noise.

All you have to do is to provide a file that contain these rules.

Example config

1<plugin>
2     <groupId>org.codehaus.mojo</groupId>
3     <artifactId>versions-maven-plugin</artifactId>
4     <version>${mvn.versions.plugin}</version>
5     <configuration>
6        <allowSnapshots>false</allowSnapshots>
7        <rulesUri>file:///${session.executionRootDirectory}/mvn-version-plugin-rules.xml</rulesUri>
8     </configuration>
9</plugin>

The line is a clean maven way - to define where the rule file is. In my case its on the root of the service (next to pom.xml)

1  <rulesUri>file:///${session.executionRootDirectory}/mvn-version-plugin-rules.xml</rulesUri>

The actual rule file:

1<!--This is only used for the maven-versions plugin - is not affecting dependency management resolution-->
2<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3         comparisonMethod="maven"
4         xmlns="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0"
5         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">
6    <ignoreVersions>
7        <ignoreVersion type="regex">.*[-_\.](alpha|Alpha|ALPHA|b|beta|Dev|Beta|BETA|rc|RC|M|EA)[-_\.]?[0-9]*</ignoreVersion>
8    </ignoreVersions>
9</ruleset>

Not bad!

References: