mojohaus / versions

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

Should detect requireMavenVersion by rules not by id #1034

Closed onacit closed 4 months ago

onacit commented 6 months ago

When maven-enforcer-plugin configured like this,

            <execution>
              <id>enforce-require-maven-version</id>
              <goals>
                <goal>enforce</goal>
              </goals>
              <configuration>
                <rules>
                  <requireMavenVersion>
                    <version>[3.6.3,)</version>
                  </requireMavenVersion>
                </rules>
              </configuration>
            </execution>

The display-plugin-updates complains.

[ERROR] Project requires an incorrect minimum version of Maven.
[ERROR] Update the pom.xml to contain maven-enforcer-plugin to
[ERROR] force the Maven version which is needed to build this project.
[ERROR] See https://maven.apache.org/enforcer/enforcer-rules/requireMavenVersion.html
[ERROR] Using the minimum version of Maven: 3.2.5

I managed to find the cause. I need to change the execution id like this.

            <execution>
              <id>enforce-maven</id> <!-- this is required -->
              <goals>
                <goal>enforce</goal>
              </goals>
              <configuration>
                <rules>
                  <requireMavenVersion>
                    <version>[3.6.3,)</version>
                  </requireMavenVersion>
                </rules>
              </configuration>
            </execution>

Should find the requireMavenVersion rule not seeking the execution id

slawekjaranowski commented 6 months ago

Execution ID should be not matter.

I don't see usage of execution ID in code:

https://github.com/mojohaus/versions/blob/master/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/MinimalMavenBuildVersionFinder.java

But to be sure we can prapare a UnitTest or change excution ID in existing IT.

onacit commented 6 months ago

@slawekjaranowski Thank you for your comment. I created a simple repository contains two pom files, namely pom1.xml and pom2.xml.

https://github.com/onacit/mojohaus-versions-issues-1034

diff pom1.xml pom2.xml 
379,380c379,380
<               <id>enforce-require-maven-version</id>
<               <!--id>enforce-maven</id-->
---
>               <!--id>enforce-require-maven-version</id-->
>               <id>enforce-maven</id>

I could reproduce the different output.

$ mvn -f pom1.xml versions:display-plugin-updates
...
[ERROR] Project requires an incorrect minimum version of Maven.
[ERROR] Update the pom.xml to contain maven-enforcer-plugin to
[ERROR] force the Maven version which is needed to build this project.
[ERROR] See https://maven.apache.org/enforcer/enforcer-rules/requireMavenVersion.html
[ERROR] Using the minimum version of Maven: 3.2.5
...

$ mvn -f pom2.xml versions:display-plugin-updates
...
[INFO] BUILD SUCCESS
...
slawekjaranowski commented 5 months ago

@onacit thanks for reproduce.

Can you clear your examples poms to have only enforcer configuration without parent and any other stuff.

onacit commented 5 months ago

@slawekjaranowski The parent! Yes, the parent might the problem which has a different execution id.

That's why I keep getting the warning message for all my repositories which each refers the same parent.

Can we resolve this issue, with the parent configured, as a specific case?

jarmoniuk commented 4 months ago

Hi. I have looked into this, but I can't seem to be able to reproduce the reported issue. Please try to isolate the issue, create a small pom.xml without any parent. If you insist of testing a case with a parent, please create two pom.xml files, one being a parent of another, and test using them. Please don't refer to any files in any remote repository. Thanks.