简体   繁体   中英

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?

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()
}

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'
    }
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM