Skip to content

Force forked JVM mode for Maven 4 ITs - #3448

Open
gnodet wants to merge 1 commit into
masterfrom
quick-fix/maven4-it-workaround
Open

gnodet wants to merge 1 commit into
masterfrom
quick-fix/maven4-it-workaround

Conversation

@gnodet

@gnodet gnodet commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Re-rolls Guillaume's Maven 4 IT workaround as a standalone PR against master so it can't get lost in future rebases of #3352.

  • Force forked JVM for Maven 4: maven-verifier 2.0.0-M1's embedded mode reflects on MavenCli.doMain(...), which Maven 4 replaced with MavenCling (incompatible signature → NoSuchMethodException → 437 IT failures). MavenLauncher now detects Maven 4 by checking for maven-cli-*.jar in $MAVEN_HOME/lib/ and forces forkJvm=true, bypassing the broken reflection entirely.
  • Fix CountdownCloseable spurious wakeup: awaitClosed() used if instead of while to guard Object.wait(), violating the JLS contract. Could explain intermittent CommandlineExecutorTest failures.

This is a short-term workaround. The long-term fix is migrating from the deprecated maven-verifier to maven-executor which natively supports both Maven 3.x and 4.x (apache/maven-verifier#186).

Context: #3352 (comment)

Test plan

  • Maven 3 ITs remain unaffected (isMaven4() returns false, forkJvm stays false)
  • Maven 4 ITs no longer fail with NoSuchMethodException (forked mode bypasses embedded reflection)
  • CountdownCloseable.awaitClosed() is robust against JLS spurious wakeups

🤖 Generated with Claude Code

…ious wakeup

maven-verifier 2.0.0-M1's embedded mode uses reflection to call
MavenCli.doMain(), but Maven 4 replaced that class with MavenCling
which has an incompatible method signature, causing all ITs to fail
with NoSuchMethodException when run against Maven 4.

Add isMaven4() detection in MavenLauncher that checks for
maven-cli-*.jar in $MAVEN_HOME/lib/ (a Maven 4-only artifact)
and forces forkJvm=true, bypassing the broken reflection path.
This is a short-term workaround until surefire migrates from
maven-verifier to maven-executor (apache/maven-verifier#186).

Also fix a pre-existing race condition in CountdownCloseable where
awaitClosed() used 'if' instead of 'while' to guard Object.wait(),
making it vulnerable to spurious wakeups per the JLS.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet gnodet mentioned this pull request Aug 27, 2026
@slachiewicz

Copy link
Copy Markdown
Member

#3484 replaces the surefire-its fixture's launcher with maven-executor 1.0.0, whose embedded mode starts Maven 4 through MavenCling, so the MavenLauncher part of this PR becomes unnecessary once it lands. The CountdownCloseable change is independent and still needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants