Why do Gradle docs specify "junit-platform-launcher" for JUnit 5 tests?

The Testing in Java & JVM projects documentation suggests the following dependencies.

dependencies {
    testImplementation("org.junit.jupiter:junit-jupiter:5.7.1")
    testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

However, my testing shows that only junit-jupiter is required in order to run unit tests:

  • via the Gradle test task
  • in IntelliJ IDEA

Here’s my example build.gradle.kts.

plugins {
    java
}

repositories {
    mavenCentral()
}

dependencies {
    testImplementation("org.junit.jupiter:junit-jupiter:5.10.0")
}

tasks.withType<Test>().configureEach {
    useJUnitPlatform()
}

What am I missing here? Why is junit-platform-launcher a suggested dependency, when it’s not required to run tests?

Maybe it should simply show testRuntimeOnly? Or maybe it was necessary but is not anymore? Or maybe it is just a doc bug?

I suggest you open an issue on GitHub, then the Gradle folks can have a look and clarify or fix it.

Good shout! Gradle team successfully poked.

2 Likes

I noticed this in Gradle 8 as well:

dependencies {
    …
    testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
    …
}

And did you read the response in the issue?
It is explained there and in the docs. :wink: