Version number rules

Introduction

Notice: The limitations explained in this paragraph were true in Maven 2.x, but have been fixed in Maven 3.x (see Maven Versioning Wiki page for more details)

The current implementation of the Maven Version Order Specification will have a very specific format:

<MajorVersion [> . <MinorVersion [> . <IncrementalVersion ] ] [> - <BuildNumber | Qualifier ]>

Where MajorVersion, MinorVersion, IncrementalVersion and BuildNumber are all numeric and Qualifier is a string. If your version number does not match this format, then the entire version number is treated as being the Qualifier.

If your version numbers do not match this scheme, you may face issues with

  • version ranges (unfortunately there is nothing that the versions-maven-plugin can do to help you with your problems with version ranges and your version numbering scheme… well you could replace your version ranges with properties and use the update-properties goal)
  • goals in this plugin that sort versions, for example update-properties (you can do things to help with these kinds of problems)

Since version 2.19.0, versions-maven-plugin only uses the Maven version numbering scheme, explained above. numeric and mercury version schemes have been abandoned.

The versions-maven-plugin will assume that all version numbers follow the maven scheme unless you tell it otherwise.

Pre-release versions

Alpha, beta, milestone, release candidate, preview and early-access versions, such as 4.0.0-beta-4, 2.0.0-M1 or 3.34.0.CR1, are not offered by default. A version is a pre-release when its Maven canonical form holds one of the qualifiers alpha, beta, milestone or rc (which also cover a1, b1, M1 and CR1), or preview, ea or pre.

When the current version is itself a pre-release or a snapshot, the pre-releases of its own release line are still offered: from 4.0.0-beta-3 the plugin offers 4.0.0-beta-4 and 4.0.0, but not 4.1.0-M1 or 5.0.0-alpha1.

To offer every pre-release, set allowPreReleases:

mvn versions:display-dependency-updates -DallowPreReleases=true

Snapshots are governed separately by allowSnapshots, and the ignored versions described below apply on top.

rules.xml

To specify ignored versions, you may define a rule-set xml file, use the ruleSet element in the versions-maven-plugin plugin configuration, or specify ignored versions via the maven.version.ignore property.

Using the rules.xml file

The rules.xml file should conform to the xsd specified in the example below.

<ruleset xmlns="https://www.mojohaus.org/VERSIONS/RULE/3.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="https://www.mojohaus.org/VERSIONS/RULE/3.0.0 https://www.mojohaus.org/versions/versions-model/xsd/rule-3.0.0.xsd">
  <rules>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>versions-maven-plugin</artifactId>
    <ignoreVersions>
      <type>range</type>
      <version>(,2.16.0]</version>
    </ignoreVersions>
  </rules>
  <ignoreVersions>
    <ignoreVersion>
      <type>regex</type>
      <version>(.+-SNAPSHOT|.+-M\d)</version>
    </ignoreVersion>
  </ignoreVersions>
</ruleset>

The rule-set files must match the XSD schema.

You can then use the rulesUri parameter to specify the rule-set to be used by the versions-maven-plugin.

Note: the groupId attribute in the rule elements has a lazy .* at the end, such that com.mycompany will match com.mycompany, com.mycompany.foo, com.mycompany.foo.bar, etc.

Using the ruleSet element in the POM

As an alternative to providing a separate rules.xml file, starting with version 2.13.0 it is possible to provide the ruleSet element directly in the POM. The structure is somewhat similar to the rules.xml file:

<project>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>versions-maven-plugin</artifactId>
        <version>2.25.2</version>
        <configuration>
          <ruleSet>
            <!-- zero or more elements -->
            <ignoreVersions>
              <!-- zero or more elements -->
              <ignoreVersion>
                <version>1.0.0</version>
              </ignoreVersion>
              <ignoreVersion>
                <!-- can be either: 'exact' (default), 'regex' or 'range' -->
                <type>regex</type>
                <version>(.+-SNAPSHOT|.+-M\d)</version>
              </ignoreVersion>
              <ignoreVersion>
                <type>regex</type>
                <version>.+-(alpha|beta).+</version>
              </ignoreVersion>
              <ignoreVersion>
                <type>range</type>
                <version>[2.0,)</version>
              </ignoreVersion>
            </ignoreVersions>

          <!-- zero or more elements -->
          <rules>
            <!-- zero or more elements -->
            <rule>
              <!-- if provided, restricts the groupId for the rule -->
              <groupId>org.codehaus.mojo</groupId>

              <!-- if provided, restricts the artifactId for the rule -->
              <artifactId>versions-maven-plugin</artifactId>

              <!-- syntax the same as for the general ignoreVersions -->
              <ignoreVersions>
                ...
              </ignoreVersions>
            </rule>
          </rules>
      </ruleSet>

Using the maven.version.ignore property

The maven.version.ignore property can list comma-separated list of global version regex patterns, which will be ignored when considering available versions.

Examples:

  • 1.0.0
  • .+-SNAPSHOT
  • (.+-SNAPSHOT|.+-M\d),.+-(alpha|beta).+,3.0.0

Using the Dependabot configuration

If the project already tells Dependabot which versions to skip, the plugin can apply the same ignore entries, so that a manual update run and Dependabot stay in step:

mvn versions:use-latest-releases -Dversions.dependabotConfig=.github/dependabot.yml

A relative path is resolved against the multi-module project directory. The plugin reads the package-ecosystem: maven entries whose target-branch is the branch checked out in that file's git working tree, or the branch given with -Dversions.dependabotTargetBranch. If no entry names the branch, the entries without a target-branch apply.

Dependabot reads its configuration from the default branch only, so on a maintenance branch the file may be missing. Export it from the default branch and name the maintenance branch explicitly:

git show origin/master:.github/dependabot.yml > /tmp/dependabot.yml
mvn versions:display-dependency-updates -Dversions.dependabotConfig=/tmp/dependabot.yml \
    -Dversions.dependabotTargetBranch=maven-3.10.x

As in Dependabot, dependency-name is matched case-insensitively against the whole groupId:artifactId, and * matches any characters, including :. Every matching item applies, on top of the best-fitting rule from ruleSet or rulesUri and of maven.version.ignore:

Dependabot versions item Ignored versions
[1.3.0,) the Maven range, plus the pre-releases of its lower bound such as 1.3.0-beta1
>= 5.0.0, >= 1.0, < 2.0 the equivalent Maven range
1.2.+ [1.2,1.3)
1.2.3 that version
no versions and no update-types every version

update-types is skipped with a warning: it depends on the version in use, which a static rule cannot express. An item that sets versions as well still applies its versions.

Ignoring certain versions

It is possible to ignore versions on a global and on a per-rule basis.

The other methods—via the <ruleSet> element and the maven.version.ignore property—have been explained above. The rules.xml example below demonstrates both global and per-rule version ignoring:

<ruleset xmlns="https://www.mojohaus.org/VERSIONS/RULE/3.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="https://www.mojohaus.org/VERSIONS/RULE/3.0.0 https://www.mojohaus.org/versions/versions-model/xsd/rule-3.0.0.xsd">
  <ignoreVersions>
    <ignoreVersion type="regex">.*-beta</ignoreVersion>
  </ignoreVersions>
  <rules>
    <rule groupId="com.mycompany.maven">
      <ignoreVersions>
        <ignoreVersion type="regex">.*-RELEASE</ignoreVersion>
        <ignoreVersion type="range">[2.0.0,)</ignoreVersion>
        <ignoreVersion>2.1.0</ignoreVersion>
      </ignoreVersions>
    </rule>
  </rules>
</ruleset>

Note: it is possible to ignore versions using regular expressions.

If you have your ruleset xml file hosted at, for example, http://www.mycompany.com/maven-version-rules.xml then the following configuration in your corporate pom would ensure that all projects use this rule set.

<project>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>versions-maven-plugin</artifactId>
        <version>2.25.2</version>
        <configuration>
          ...
          <rulesUri>http://www.mycompany.com/maven-version-rules.xml</rulesUri>
          ...
        </configuration>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>

You can provide your ruleset xml file also within a jar, if you want to distribute your ruleset xml as Maven artifact. Therefore you have to declare the containing jar as direct dependency of the versions-maven-plugin and to use classpath as protocol.

<project>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>versions-maven-plugin</artifactId>
        <version>2.25.2</version>
        <configuration>
          ...
          <rulesUri>classpath:///package/foo/bar/rules.xml</rulesUri>
          ...
        </configuration>
        <dependencies>
            <dependency>
                <groupId>com.mycompany</groupId>
                <artifactId>version-rules</artifactId>
                <version>1.0</version>
            </dependency>
        </dependencies>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>