maven-git-versioning-extension icon indicating copy to clipboard operation
maven-git-versioning-extension copied to clipboard

Maven 4.0.0-x compatibility

Open sureshg opened this issue 1 year ago • 6 comments
trafficstars

Getting this error when running on maven 4.0.0-Beta4

$ ./mvnw wrapper:wrapper -Dmaven=4.0.0-beta-4
Exception in thread "main" java.lang.AbstractMethodError: Receiver class me.qoomon.maven.gitversioning.GitVersioningModelProcessor does not define or inherit an implementation of the resolved method 'abstract java.nio.file.Path locateExistingPom(java.nio.file.Path)' of interface org.apache.maven.model.locator.ModelLocator.
        at org.apache.maven.model.locator.ModelLocator.locateExistingPom(ModelLocator.java:64)
        at org.apache.maven.cli.MavenCli.determinePom(MavenCli.java:1435)
        at org.apache.maven.cli.MavenCli.populateRequest(MavenCli.java:1323)
        at org.apache.maven.cli.MavenCli.populateRequest(MavenCli.java:1297)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:208)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        at java.base/java.lang.reflect.Method.invoke(Method.java:573)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:255)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:201)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:361)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:314)
`

sureshg avatar Sep 02 '24 20:09 sureshg

Although I fixed this issue, the extension is not loaded anymore. I assume maven 4.0.0 has changed how core extensions are working or how DI is done.

qoomon avatar Sep 03 '24 11:09 qoomon

A couple of days ago I wanted to give Maven 4.0.0-rc-1 a try on a multi-module project and had to find out that the extension doesn't work anymore, neither with rc-1 nor with the recently released rc-2. I asked on the mailing list, and got the following respons from @cstamas:

In short, the extension is not compatible with Maven4 due this "trick": https://github.com/qoomon/maven-git-versioning-extension/blob/master/src/main/java/me/qoomon/maven/gitversioning/GitVersioningModelProcessor.java

To properly support Maven4, this extension would need to be "enabled" for Maven4, very similar like Nisse was recently: https://github.com/maveniverse/nisse/commit/a24a8e90e39d50ae479e5e3e92b6ad643849e147#diff-eaf45ebe6b14a5aaad3400949a1a9a22c8b09f49acc9683dbb28eaf21bf93895

In short: Maven4 PropertyContributor SPI should be used instead.

See https://lists.apache.org/thread/z3sy75xvwrfcwpnnh9gs4f2x0qv7dgrs

theit avatar Dec 18 '24 08:12 theit

@theit thanks for details, I'll see if I can adjust this extension accordingly.

qoomon avatar Dec 18 '24 10:12 qoomon

So if I got this right I need to implement following interface instead of ModelProcessor ModelParser

qoomon avatar Dec 18 '24 10:12 qoomon

The above problem seems resolved in Maven 4.0.0-rc-3.

However, I see a regression concerning the evaluation of ${project.version}.

Maven 3.9.9:

./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout
2.12.0-SNAPSHOT

Maven 4.0.0-rc-3:

./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout
[INFO] [stdout] 1.0.0

More strangely, still with Maven 4.0.0-rc-3:

cd target 
../mvnw help:evaluate -Dexpression=project.version -q -DforceStdout
[INFO] [stdout] 1

Because of this, the extension is not ready for use with Maven 4. Or am I missing something?

jbmestelan avatar May 26 '25 08:05 jbmestelan

More detailed log:

[WARNING] [stderr] SLF4J(W): Using deprecated property org.slf4j.simpleLogger.log.me.qoomon.maven.gitversioning. Please migrate to maven.logger.log.me.qoomon.maven.gitversioning
[INFO] 
[INFO] 1 problem was encountered while building the effective settings (use -e to see details)
[INFO] 
[INFO] Scanning for projects...
[WARNING] 
[WARNING] 1 problem was encountered while building the effective model for 'redacted-api:jar:1.0.0' (use -e to see details)
[WARNING] 
[WARNING] Total model problems reported: 1
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[DEBUG] skip model - no project model pom file
[INFO] 
[INFO] -----------------------------------< redacted-api >-----------------------------------
[INFO] Building redacted-api 1.0.0
[INFO]   from pom.xml
[INFO] ---------------------------------------------------------[ jar ]----------------------------------------------------------
[INFO] 
[INFO] --- help:3.5.1:evaluate (default-cli) @ redacted-api ---
[INFO] No artifact parameter specified, using 'redacted-api:jar:1.0.0' as project.
[INFO] 
1.0.0
[INFO] --------------------------------------------------------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] --------------------------------------------------------------------------------------------------------------------------
[INFO] Total time:  2.149 s
[INFO] Finished at: 2025-05-26T10:52:34+02:00
[INFO] --------------------------------------------------------------------------------------------------------------------------

Note: the warning is caused by this issue with Maven 4: https://github.com/apache/maven-apache-parent/issues/265. It does not seem relevant to the current problem.

jbmestelan avatar May 26 '25 08:05 jbmestelan