Skip to content

Conversation

@marcphilipp
Copy link
Member

The Launcher now checks for classpath alignment in case a LinkageError
such as a ClassNotFoundError is thrown from one of the methods of the
Launcher or TestEngine interfaces. If it finds unaligned versions, it
wraps the LinkageError in a JUnitException with a message listing the
detected versions and a link to the User Guide.

Resolves #3935.

The Launcher now checks for classpath alignment in case a LinkageError
such as a ClassNotFoundError is thrown from one of the methods of the
Launcher or TestEngine interfaces. If it finds unaligned versions, it
wraps the LinkageError in a JUnitException with a message listing the
detected versions and a link to the User Guide.

Resolves #3935.
@marcphilipp marcphilipp self-assigned this Jan 12, 2025
@marcphilipp marcphilipp requested a review from a team January 12, 2025 16:57
assertEquals(1, result.exitCode());
assertEquals("", result.stdErr());
assertTrue(result.stdOutLines().contains("[INFO] BUILD FAILURE"));
assertThat(result.stdOut()) //
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sample Maven output:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.325 s
[INFO] Finished at: 2025-01-12T17:47:19+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.5.2:test (default-test) on project maven-starter: 
[ERROR] 
[ERROR] See /tmp/junit-11800371830507414181/target/surefire-reports for the individual test results.
[ERROR] See dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] There was an error in the forked process
[ERROR] org.junit.platform.commons.JUnitException: The wrapped NoClassDefFoundError is likely caused by the versions of JUnit jars on the classpath/module path not being properly aligned. 
[ERROR] Please ensure consistent versions are used (see https://junit.org/junit5/docs/5.12.0-SNAPSHOT/user-guide/#dependency-metadata).
[ERROR] The following versions were detected:
[ERROR] - org.junit.platform.commons: 1.11.4
[ERROR] - org.junit.platform.engine: 1.12.0-SNAPSHOT
[ERROR] - org.junit.platform.launcher: 1.12.0-SNAPSHOT

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "The following conflicting versions were detected"?

Out of curiosity, why does the link point to 5.12.0-SNAPSHOT instead of snapshot? Is that version pulled from a JAR manifest?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why does the link point to 5.12.0-SNAPSHOT instead of snapshot? Is that version pulled from a JAR manifest?

Never mind: I just noticed in the code that the latter is the case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "The following conflicting versions were detected"?

Done in d11a104

Comment on lines +56 to +57
Function<String, Package> packageLookup = name -> ReflectionSupport.findMethod(ClassLoader.class,
"getDefinedPackage", String.class) //
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Java 9+

Comment on lines +56 to +59
Function<String, Package> packageLookup = name -> ReflectionSupport.findMethod(ClassLoader.class,
"getDefinedPackage", String.class) //
.map(m -> (Package) ReflectionSupport.invokeMethod(m, classLoader, name)) //
.orElseGet(() -> getPackage(name));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only works for packages for which classes have already been loaded by the class loader and thus is likely to contain the conflicting JARs.

Copy link
Member

@sbrannen sbrannen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only skimmed over the implementation and tests, but the resulting output looks good. 👍

Thanks, Marc

@marcphilipp marcphilipp merged commit 1a03531 into main Jan 15, 2025
15 checks passed
@marcphilipp marcphilipp deleted the marc/3935-classpath-alignment-check branch January 15, 2025 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Raise awareness of version upgrade strategies

4 participants