eastwater
eastwater

Reputation: 5572

Junit 5 gradle plugin not found

Try to use junit 5 with gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0'
    }
}

apply plugin: 'java-library'
apply plugin: 'org.junit.platform.gradle.plugin'
...

Error:

Plugin with id 'org.junit.platform.gradle.plugin' not found.

Gradle version 4.0. What is wrong?

Upvotes: 8

Views: 8384

Answers (3)

LazerBanana
LazerBanana

Reputation: 7211

Since version 4.6 for Gradle, there is no need for plugins anymore

Gradle supports Junit5 natively just do:

dependencies {       
    testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
    testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"

    testRuntimeOnly "org.junit.vintage:junit-vintage-engine:4.12.0"
    testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
}

test {
    useJUnitPlatform {
        includeEngines 'junit-jupiter', 'junit-vintage'
    }
}

Upvotes: 6

Alex Sartan
Alex Sartan

Reputation: 195

Are you placing the above code in a separate file that you are then including in the main build.gradle via apply from: ...? If so, you may be running up against a bug in Gradle where a plugin id cannot be used in external scripts. Instead, you have to specify the fully qualified class name.

More info:

https://github.com/gradle/gradle/issues/1262

https://discuss.gradle.org/t/how-do-i-include-buildscript-block-from-external-gradle-script/7016

Upvotes: 1

Sam Brannen
Sam Brannen

Reputation: 31187

You have to include a repositories section outside the buildscript block as well:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0'
    }
}

apply plugin: 'java-library'
apply plugin: 'org.junit.platform.gradle.plugin'

repositories {
    mavenCentral()
}

Upvotes: 5

Related Questions