Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OutputDirectoryProvider not available; probably due to unaligned versions of the junit-platform-engine and junit-platform-launcher jars on the classpath/module path. #4374

Closed
swaechter opened this issue Mar 6, 2025 · 5 comments

Comments

@swaechter
Copy link

swaechter commented Mar 6, 2025

When switching from JUnit 5.11.4 to 5.12.0, all my tests fail at runtime:

Output:

PS SNIPPED_PATH\junittest> .\gradlew.bat build
> Task :test FAILED

[Incubating] Problems report is available at: file:///SNIPPED_PATH/junittest/build/reports/problems/problems-report.html

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///SNIPPED_PATH/junittest/build/reports/tests/test/index.html

* Try:
> Run with --scan to get full insights.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.13/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD FAILED in 2s
3 actionable tasks: 3 executed
PS SNIPPED_PATH\junittest>

Stacktrace:

org.gradle.api.internal.tasks.testing.TestSuiteExecutionException: Could not complete execution for Gradle Test Executor 1.
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:65)
	at [email protected]/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at [email protected]/java.lang.reflect.Method.invoke(Method.java:580)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:92)
	at jdk.proxy1/jdk.proxy1.$Proxy4.stop(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:200)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:132)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:103)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:63)
	at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:121)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
	at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
	at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
Caused by: org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-jupiter' failed to discover tests
	at app//org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:160)
	at app//org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverSafely(EngineDiscoveryOrchestrator.java:134)
	at app//org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:108)
	at app//org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:80)
	at app//org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:110)
	at app//org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
	at app//org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:124)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:99)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:94)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:63)
	... 16 more
Caused by: org.junit.platform.commons.JUnitException: OutputDirectoryProvider not available; probably due to unaligned versions of the junit-platform-engine and junit-platform-launcher jars on the classpath/module path.
	at app//org.junit.platform.engine.EngineDiscoveryRequest.getOutputDirectoryProvider(EngineDiscoveryRequest.java:94)
	at app//org.junit.jupiter.engine.JupiterTestEngine.discover(JupiterTestEngine.java:67)
	at app//org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:152)
	... 26 more

Gradle wrapper version:

PS SNIPPED_PATH\junittest> .\gradlew.bat --version

------------------------------------------------------------
Gradle 8.13
------------------------------------------------------------

Build time:    2025-02-25 09:22:14 UTC
Revision:      073314332697ba45c16c0a0ce1891fa6794179ff

Kotlin:        2.0.21
Groovy:        3.0.22
Ant:           Apache Ant(TM) version 1.10.15 compiled on August 25 2024
Launcher JVM:  21.0.4 (Eclipse Adoptium 21.0.4+7-LTS)
Daemon JVM:    C:\Program Files\Eclipse Adoptium\jdk-21.0.4.7-hotspot (no JDK specified, using current Java home)
OS:            Windows 11 10.0 amd64

How to reproduce the problem (Reproducer: https://github.com/swaechter/junittest):

1.) Create a new Gradle project and update the Gradle wrapper to 8.13

2.) Create a new test case:

package com.swaechter;

import org.junit.jupiter.api.Test;

public class ExampleTest {

    @Test
    public void testHello() {
        System.out.println("Hello World");
    }
}

3.) Update the build.gradle.kts file:

plugins {
    id("java")
}

group = "ch.swaechter"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    // Switch to JUnit version 5.12.0 to reproduce the error
    testImplementation(platform("org.junit:junit-bom:5.11.4"))
    //testImplementation(platform("org.junit:junit-bom:5.12.0"))
    testImplementation("org.junit.jupiter:junit-jupiter")
}

tasks.test {
    useJUnitPlatform()
}

4.) Toggle between JUnit version 5.11.4 and 5.12.0 and run the build/test command to reproduce the error.

Remarks:

  • The problem also happens with older versions of the Gradle wrapper
  • The problem also happens when using Java 23
  • The problem happens from the command line and also from IntelliJ IDEA
@marcphilipp
Copy link
Member

The root cause is that Gradle uses an old version of junit-platform-launcher if there is no explicit dependency on it on the test runtime classpath.

Please add a testRuntimeOnly("org.junit.platform:junit-platform-launcher") dependency. We've updated the User Guide a few days ago to reflect that.

@sbrannen
Copy link
Member

sbrannen commented Mar 6, 2025

Closing this as a:

Specifying a testRuntimeOnly dependency on junit-platform-launcher should resolve the issue.

In the future, please search the issue tracker for related issues before creating a new issue.

Thanks

@sbrannen
Copy link
Member

sbrannen commented Mar 6, 2025

Oops... looks like @marcphilipp and I were typing at the same time. 😉

@swaechter
Copy link
Author

swaechter commented Mar 7, 2025

Dear Marc and Sam. Thanks a lot for your fast reply and the explanation (Also in the linked issue regarding the new API). I was reading the changelog + using a time fixed Google search, but nothing showed up. But as you said, the issue search would have provided several of these issues. Sorry, my bad - have a nice weekend :)

@marcphilipp
Copy link
Member

Sorry, my bad - have a nice weekend :)

No worries! You, too!

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

No branches or pull requests

3 participants