36

I have an issue concerning the plugin versions.

When it generates a report with the goal:

mvn versions:display-dependency-updates

It suggest is a lot of libraries that with beta or alpha versions.

 org.hibernate:hibernate-validator ......... 4.2.0.Final -> 4.3.0.Beta1

The issue is that event if the goal of this plugin is to show the very latest versions of each dependency, I don't want to use beta/alpha versions for production code. But I don't want to search manually the last stable version neither.

I've tried the 'comparisonMethod' option: numeric, maven, etc. No success whatsoever.

Any ideas for the plugin 'versions' to show the latests available versions of dependencies, but without including beta/alpha?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ivan Tamayo
  • 361
  • 3
  • 5

1 Answers1

31

You can configure the versions plugin like this:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>versions-maven-plugin</artifactId>
    <version>2.1</version>
    <configuration>
        <rulesUri>someUrl</rulesUri>
    </configuration>
</plugin>

someUrl can also be a file URL. The syntax of the rules file is given in http://www.mojohaus.org/versions-maven-plugin/version-rules.html, it may contain something like this:

<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>
    <ignoreVersion type="regex">.*-beta.</ignoreVersion>
    <ignoreVersion type="regex">.*_ALPHA</ignoreVersion>
  </ignoreVersions>
</ruleset>
Michael Piefel
  • 18,660
  • 9
  • 81
  • 112
  • 3
    Nice explanation. I finally updated my common POM using this example. [This commit](https://github.com/jjzabkar/jjz-base-pom/commit/faac44c8a6ca0831fcdd89459628c77363045bb1) shows the implementation. – JJ Zabkar Mar 04 '14 at 16:53
  • 1
    Your second code snippet isn't well-formed, there is an 'e' lacking in the closing tag. :-) – mle Apr 13 '15 at 10:42
  • 2
    A shame it took over a year for anyone to notice. – Michael Piefel Apr 13 '15 at 11:07
  • 17
    The following ignoreVersion rule removes most alpha, beta etc stuff: `.*[-_\.](alpha|Alpha|ALPHA|b|beta|Beta|BETA|rc|RC|M|EA)[-_\.]?[0-9]*` – Philip Helger Aug 31 '16 at 11:18
  • Is there any way to use ruleset file inside project? I need project relative rulesUri – hurelhuyag Feb 13 '19 at 10:13
  • 8
    It’s an URI, so use a file URI: `file:///${project.basedir}/maven-version-rules.xml` – Michael Piefel Feb 13 '19 at 10:48
  • 1
    Does anyone have experience in using this with multi-module projects? Can I specify a (relative) path to the rules file in such a case? I put mine in the parent module's root and `ln` it into every submodule. That works but might not be the most elegant approach. – martin Jun 25 '19 at 07:59
  • 4
    I have a property `file:///${project.basedir}/maven-version-rules.xml` in the parent and `file:///${project.basedir}/../maven-version-rules.xml` in all children. That way, I need only the configuration of the plugin in the parent. – Michael Piefel Jun 25 '19 at 09:22
  • ruleset has no closing element, and rules has no opening element. – Tilman Hausherr Apr 11 '20 at 11:45
  • 2
    I suggest `${project.baseUri}/maven-version-rules.xml` and `(?i).*[-_\.](alpha|b|beta|rc|m|ea)[-_\.]?[0-9]*` which is case-insensitive. – Robert Hume Apr 29 '20 at 20:59