junit-pioneer: NoClassDefError with JUnit Jupiter 5.7.0

Hi, I want to use 0.9.1 JUnit Pioneer’s @org.junitpioneer.jupiter.SetSystemProperty but it currently fails with JUnit Jupiter 5.7.0:

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/Cellar/maven-deluxe/3.6.3-0/libexec
Java version: 11.0.8, vendor: N/A, runtime: /usr/local/Cellar/openjdk@11/11.0.8/libexec/openjdk.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.7", arch: "x86_64", family: "mac"
[...]
WARNING: TestEngine with ID 'junit-jupiter' failed to execute tests
java.lang.NoClassDefFoundError: org/junit/platform/commons/util/UnrecoverableExceptions
	at org.junit.jupiter.engine.support.OpenTest4JAndJUnit4AwareThrowableCollector.createAbortedExecutionPredicate(OpenTest4JAndJUnit4AwareThrowableCollector.java:58)
	at org.junit.jupiter.engine.support.OpenTest4JAndJUnit4AwareThrowableCollector.<clinit>(OpenTest4JAndJUnit4AwareThrowableCollector.java:41)
	at org.junit.jupiter.engine.support.JupiterThrowableCollectorFactory.createThrowableCollector(JupiterThrowableCollectorFactory.java:34)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:78)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:220)
	at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:188)
	at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:202)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:181)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
	at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invokeAllTests(JUnitPlatformProvider.java:150)
	at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:124)
	at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)
	at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.commons.util.UnrecoverableExceptions
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	... 18 more

It does not fail with JUnit Jupiter 5.6.2.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 23 (22 by maintainers)

Commits related to this issue

Most upvoted comments

@fbiville I think you can fix this by adding junit-bom to your project. While it’s briefly mentioned in https://junit.org/junit5/docs/current/user-guide/#dependency-metadata-junit-bom in neither the case of Maven or Gradle does it tell you how to actually do it. Add to your pom.xml and let us know if it fixes the issue for you:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.junit</groupId>
            <artifactId>junit-bom</artifactId>
            <version>5.7.0</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

I have created #346. While, not a necessary change, it is probably safer to do so that the versions of jupiter and platform are automatically aligned for all possible dependencies.

So the issue is caused by mixed dependency versions. This happens because I only declared a few junit dependencies and not junit-platform-commons explicitly which got brought in transitively through junit-pioneer.

The way to prevent this is to depend on junit-bom instead of separate dependencies in my project as this will keep versions in sync with one another. See https://github.com/project-ncl/build-finder/pull/229/files.

@Bukama I found a difference, after upgrading from 0.9.0 -> 0.9.1 we have

junit-platform-commons:jar:1.5.2:test

instead of

junit-platform-commons:jar:1.7.0:test

@Bukama Check the log. The build somehow passes but test coverage is reported as 0% due to the error described in this issue. This is how I noticed it, the check for my test coverage failed as it dropped from 70% to 0% after this PR.