Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/maven-verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ jobs:
!surefire-its/target/ConsoleOutputIT_*/target/surefire-reports/*-jvmRun*-events.bin
timeout-minutes: 600
os-matrix: '[ "ubuntu-latest", "windows-latest", "macos-latest" ]'
maven4-enabled: true
matrix-exclude: '[
{ "jdk": "11", "maven": "4.0.0-rc-5" }
]'
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public synchronized void close() throws IOException {
* @throws InterruptedException see {@link Object#wait()}
*/
public synchronized void awaitClosed() throws InterruptedException {
if (countdown > 0) {
while (countdown > 0) {
wait();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ public final class MavenLauncher {
this.resourceName = resourceName;
this.suffix = suffix != null ? suffix : "";
this.cli = cli == null ? null : cli.clone();
// by default use embedded mode
this.forkJvm = false;
// Use forked mode for Maven 4+ because maven-verifier 2.0.0-M1's embedded mode
// uses reflection against MavenCling.doMain() with an incompatible method signature.
// Once surefire migrates from maven-verifier to maven-executor, this can be removed.
this.forkJvm = isMaven4();
resetGoals();
resetCliOptions();
}
Expand Down Expand Up @@ -409,6 +411,32 @@ private static Verifier createVerifier(String basedir, String settingsFile, Stri
: new Verifier(basedir, settingsFile, false, defaultCliOptions);
}

/**
* Detects if the current Maven installation is version 4.x or later by checking for the
* presence of {@code maven-cli-*.jar} in the Maven home lib directory. Maven 4 introduced
* the {@code maven-cli} module which is not present in Maven 3.x installations.
*
* @return {@code true} if Maven 4+ is detected
*/
private static boolean isMaven4() {
String mavenHome = System.getProperty("maven.home", "");
if (mavenHome.isEmpty()) {
return false;
}
File libDir = new File(mavenHome, "lib");
if (libDir.isDirectory()) {
String[] files = libDir.list();
if (files != null) {
for (String file : files) {
if (file.startsWith("maven-cli-")) {
return true;
}
}
}
}
return false;
}

private static File settingsXmlPath() {
try {
return new File(System.getProperty("maven.settings.file")).getCanonicalFile();
Expand Down
Loading