cannot find method useJUnitPlatform for test task in gradle

If you are using IntelliJ it is worth checking which Gradle are you using for given project (can be wrapper, task, local). To do so go to Settings and search for Gradle. Then navigate to Build,Execution,Deployment -> Build Tools -> Gradle


Here is how I fixed it. I had this test task in my build.gradle:

tasks.withType(Test) {
    useJUnitPlatform()
    testLogging {
        exceptionFormat "full"
        events "started", "skipped", "passed", "failed"
        showStandardStreams true
    }
}

And I had these dependencies (You might want to refresh gradle so it takes them into account):

dependencies {
  testCompile('org.junit.jupiter:junit-jupiter-api:5.4.0')
  testRuntime('org.junit.jupiter:junit-jupiter-engine:5.4.0')
  testRuntime('org.junit.vintage:junit-vintage-engine:5.4.0')
}

Then I used the gradle wrapper (I was using gradle 4.8) so it stays stable from one computer to another:

./gradlew clean build test

Tags:

Java

Gradle