mojohaus / versions

Versions Maven Plugin
https://www.mojohaus.org/versions/versions-maven-plugin/
Apache License 2.0
338 stars 267 forks source link

Question: on ignoring versions #962

Closed skin27 closed 1 year ago

skin27 commented 1 year ago

I have a multimodule Maven project that I like to keep up-to-date with the versions plugin. When running the plugin I like to ignore versions like alpha's and snapshot. I found several resources on StackOverflow and tried to following commands:

  1. Pure command line

mvn -f ....\pom.xml versions:display-dependency-updates -Dexcludes=org.apache.camel: -DignoredVersions="1.0.1,.+-M.,.-SNAPSHOT" -DlogOutput=false

  1. With ruleset file:

mvn -f ....\pom.xml versions:display-dependency-updates -DrulesUri="file:///${parent.basedir}/rules.xml"

The rulesset file:

<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>
    <ignoreVersion type="regex">.*-alpha12</ignoreVersion>
    <ignoreVersion type="regex">.*[-_\.](alpha|Alpha|ALPHA|b|beta|Beta|BETA|rc|RC|M|EA)[-_\.]?[0-9]*</ignoreVersion>
    <ignoreVersion type="regex">(?i).*Alpha(?:-?\d+)?</ignoreVersion>
    <ignoreVersion type="regex">(?i).*a(?:-?\d+)?</ignoreVersion>
    <ignoreVersion type="regex">(?i).*Beta(?:-?\d+)?</ignoreVersion>
    <ignoreVersion type="regex">(?i).*-B(?:-?\d+)?</ignoreVersion>
    <ignoreVersion type="regex">(?i).*RC(?:-?\d+)?</ignoreVersion>
    <ignoreVersion type="regex">(?i).*CR(?:-?\d+)?</ignoreVersion>
    <ignoreVersion type="regex">(?i).*M(?:-?\d+)?</ignoreVersion>
    <ignoreVersion type="regex">4.0.0-M3</ignoreVersion>

  </ignoreVersions>
</ruleset>

The output is for example (both commands):

[INFO] --- versions-maven-plugin:2.15.0:display-dependency-updates (default-cli) @ base ---
[INFO] The following dependencies in Dependency Management have newer versions:
[INFO]   org.apache.camel:camel-amqp ....................... 3.20.4 -> 4.0.0-M3
[INFO]   org.apache.camel:camel-api ........................ 3.20.4 -> 4.0.0-M3
[INFO]   org.apache.camel:camel-arangodb ................... 3.20.4 -> 4.0.0-M3

Additional information:

JDK Version JDK 11 (Eclipse Temurin 11.0.18) OS: Windows 10 Maven version: 3.8.6 Versions plugin: 2.15.0

What am I doing wrong? What's the correct way to ignore these versions?

eitan-rosenberg commented 1 year ago

Hi,

I about 130 small projects.

A few years back I face the same problem.

What I did to write a program that collect all the dependencies and create aggregated POM and then run the org.apache.maven.shared.invoker.Invoker to do the job.

I use maven.version.rules = file:///K:/JavaAPPs/MyMaven/maven.version.rules.xml

<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 https://www.mojohaus.org/versions-maven-plugin/xsd/rule-2.0.0.xsd">

<ignoreVersions>
    <ignoreVersion type="regex">(?i).*(-alpha|.alpha|beta|-ea|-m1|-m2|-m3|-m4|cr|rc).*</ignoreVersion>
</ignoreVersions>

<rules>

    <rule groupId="org.apache.maven.archetypes" artifactId="maven-archetype-quickstart" comparisonMethod="maven">
        <ignoreVersions>
            <ignoreVersion type="regex">(?i).*</ignoreVersion>
        </ignoreVersions>
    </rule>

    <rule groupId="com.google.guava" comparisonMethod="maven">
        <ignoreVersions>
            <ignoreVersion type="regex">(?i).*(android).*</ignoreVersion>
        </ignoreVersions>
    </rule>

    <rule groupId="org.openjfx" comparisonMethod="maven">
        <ignoreVersions>
            <ignoreVersion type="regex">(?i).*(20.0.1).*</ignoreVersion>
        </ignoreVersions>
    </rule>

</rules>

Another program use a list of dependencies to scan the projects and for each found run "versions:use-next-releases"

Regards.

p.s. I will be happy to share the code. please let me know.

skin27 commented 1 year ago

That's interesting. But the question I still have, why does the default approach not work (the ignore rules and exclude parameters). Is it because submodules are used? Or is it something different?

eitan-rosenberg commented 1 year ago

I do not use submodules so I can't say. Have you tried my rules just to omit problems with regular expressions ?

eitan-rosenberg commented 1 year ago

I copied your rules. I had to change one so "-ea" will work.

<!-- <ignoreVersion type="regex">.*[-_\.](alpha|Alpha|ALPHA|b|beta|Beta|BETA|rc|RC|M|EA)[-_\.]?[0-9]*</ignoreVersion> -->
    <ignoreVersion type="regex">(?i).*(alpha|Alpha|ALPHA|b|beta|Beta|BETA|rc|RC|M|EA).*</ignoreVersion>
skin27 commented 1 year ago

I found out that (probably due to a misconfiguration) the rules.xml wasn't applied. So even when I made the XML file invalid it didn't give an error.

The configuration that worked for me was:

project pom.xml


    <properties>
        <maven.versions.rules>file:///${project.basedir}/rules.xml</maven.versions.rules>
    <properties>

        <build>
          <plugins>         
            <plugin>
                  <groupId>org.codehaus.mojo</groupId>
                  <artifactId>versions-maven-plugin</artifactId>
                  <version>2.15.0</version>
                  <configuration>
                      <rulesUri>${maven.versions.rules}</rulesUri>
                  </configuration>
            </plugin> 
        </plugins>
    </build>

pom.xml for every submodule

    <properties>
        <maven.versions.rules>file:///${project.basedir}/../rules.xml</maven.versions.rules>
    </properties>

Thanks for your help