Search code examples
javaregexgitmaven-versions-plugin

Maven-versions-plugin: regex for negating versions which do not follow a specific tag format


I am using the maven-versions-plugin with the setProperties goal. I have defined a ruleset to compare current property version with available versions containing a git branch name (a git tag), and having the following format:
<number>.<number>.<number>-<branch_name>.<number>
for example if the branch is dev I would like to match versions like 1.29.0-dev.5 and ignore any other tag like 1.28.0-release.3 or 1.8.0-prere10010.1.
The rule requires to specify the versions to ignore - so all versions that are not of the form <number>.<number>.<number>-dev.<number> should be ignored.
I have tried several regex but do not arrive to the desired result - all versions are in the list of valid versions to compare current version with

<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">
<rules>
    <rule groupId="com.abc.de" comparisonMethod="maven">
        <ignoreVersions>
            <ignoreVersion type="regex">(?!^[((\d*)\.(\d*)\.(\d*)\-dev\.(\d*))]$)</ignoreVersion>
            <ignoreVersion type="regex">null</ignoreVersion>
        </ignoreVersions>
    </rule>
</rules>

`

Could you please help writing the correct regex?


Solution

  • Try using a negative forward lookup, followed by capturing the rest of the string, in case Maven is looking for a full match:

    ^(?!\d+\.\d+\.\d+-dev\.\d+).*$