maven-mvnd icon indicating copy to clipboard operation
maven-mvnd copied to clipboard

maven enforcer plugin does not fail consistently when called with mvnd

Open sebastian-bayerl-enmacc opened this issue 4 months ago • 4 comments

Affected version

1.0.2 and 2.0.0-rc-3

Bug description

When running the maven enforcer plugin via mvnd clean validate it does not consistently fail. It correctly fails consistently on the first run. When I use mvn the enforcer successfully fails every run. Looks like there is a problem with loading the rules or the rule evaluation on later consecutive runs.

This might be related to some caching issues, maybe the following problem is similar:

https://github.com/apache/maven-mvnd/issues/841 https://github.com/takari/takari-smart-builder/pull/25

Here the setup:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <executions>
        <execution>
            <id>enforce-maven-java-version</id>
            <goals>
                <goal>enforce</goal>
            </goals>
            <phase>validate</phase>
            <configuration>
                <rules>
                    <requireMavenVersion>
                        <version>[3.9.9,)</version><!-- this version or higher is OK -->
                    </requireMavenVersion>
                    <requireJavaVersion>
                        <version>[23,24)</version> <!-- only 23 is OK -->
                    </requireJavaVersion>
                </rules>
            </configuration>
        </execution>
    </executions>
</plugin>

Here the ERROR that is produced by mvn every run and with mvnd only on the first local run, second and following run I get a [INFO] BUILD SUCCESS:

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.289 s (Wall Clock)
[INFO] Finished at: 2025-08-13T09:43:09+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:3.4.1:enforce (enforce-maven-java-version) on project enmacc-server: 
[ERROR] Rule 1: org.apache.maven.enforcer.rules.version.RequireJavaVersion failed with message:
[ERROR] Detected JDK version 24.0.2 (JAVA_HOME=/Users/sebastian.bayerl/.sdkman/candidates/java/24.0.2-amzn) is not in the allowed range [23,24).                                                                                    
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Here some additional infos:

mvn: [INFO] Using the MultiThreadedBuilder implementation with a thread count of 14 mvnd: [INFO] Using the SmartBuilder implementation with a thread count of 13

mvnd

%  mvnd --version       
Apache Maven Daemon (mvnd) 1.0.2 darwin-aarch64 native client (cccc1ec8a5b741c62b29f9fb04d37b1678a029bb)
Terminal: org.jline.terminal.impl.PosixSysTerminal with pty org.jline.terminal.impl.jni.osx.OsXNativePty
Apache Maven 3.9.9 (8e8579a9e76f7d015ee5ec7bfcdc97d260186937)
Maven home: /opt/homebrew/Cellar/mvnd@1/1.0.2/libexec/mvn
Java version: 24.0.2, vendor: Amazon.com Inc., runtime: /Users/sebastian.bayerl/.sdkman/candidates/java/24.0.2-amzn
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "15.6", arch: "aarch64", family: "mac"

mvn

%  mvn -v
Apache Maven 3.9.11 (3e54c93a704957b63ee3494413a2b544fd3d825b)
Maven home: /opt/homebrew/Cellar/maven/3.9.11/libexec
Java version: 24.0.2, vendor: Amazon.com Inc., runtime: /Users/sebastian.bayerl/.sdkman/candidates/java/24.0.2-amzn
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "15.6", arch: "aarch64", family: "mac"

sebastian-bayerl-enmacc avatar Aug 13 '25 07:08 sebastian-bayerl-enmacc

@sebastian-bayerl-enmacc can you try with -Denforcer.ignoreCache ? Also try with -X as somewhere some hint may be logged, like this one https://github.com/apache/maven-enforcer/blob/d4be5532fa112460a30c462d2ebb94fc64278075/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/internal/EnforcerRuleCache.java#L62

@gnodet This looks sus: https://github.com/apache/maven-enforcer/blob/d4be5532fa112460a30c462d2ebb94fc64278075/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/internal/EnforcerRuleCache.java#L72 The enforcer cache is tied to DI container lifecycle (which is not killed in mvnd), but rules in cache are considered as "already executed"?

cstamas avatar Sep 09 '25 09:09 cstamas

@sebastian-bayerl-enmacc can you try with -Denforcer.ignoreCache ? Also try with -X as somewhere some hint may be logged, like this one https://github.com/apache/maven-enforcer/blob/d4be5532fa112460a30c462d2ebb94fc64278075/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/internal/EnforcerRuleCache.java#L62

@gnodet This looks sus: https://github.com/apache/maven-enforcer/blob/d4be5532fa112460a30c462d2ebb94fc64278075/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/internal/EnforcerRuleCache.java#L72 The enforcer cache is tied to DI container lifecycle (which is not killed in mvnd), but rules in cache are considered as "already executed"?

Right. It should be tied to the Session, not the container. As a work around, you can try using mvnd.pluginRealmEvictPattern=mvn:maven-enforcer-plugin

gnodet avatar Sep 09 '25 09:09 gnodet

Caused by https://github.com/apache/maven-enforcer/issues/929

cstamas avatar Sep 10 '25 13:09 cstamas

https://github.com/apache/maven-enforcer/pull/930

The fix is in upcoming 3.6.2 release

cstamas avatar Sep 29 '25 10:09 cstamas

Fixed in m-enforcer-p

cstamas avatar Dec 17 '25 16:12 cstamas