Junit 5 Gradle插件未找到。

8

尝试使用gradle和junit 5:

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

错误:

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

Gradle 4.0版本有什么问题吗?

一切看起来都很好。配置看起来也没问题。你的网络连接/代理设置没有任何问题吗? - Opal
互联网正常工作。 - eastwater
你能否将 --stacktrace 添加到构建参数并发布吗? - mkobit
有相同的问题。 - Serhii Povísenko
3个回答

6
自从Gradle 4.6版本起,不再需要插件。Gradle可以本地支持Junit5,只需执行以下操作:
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'
    }
}

Gradle 4.9报错:"无法获取类型为org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler的对象的未知属性'test'。" - ildar ishalin
1
现在显示:"在类型为org.gradle.api.Project的项目':app'中,无法找到参数为[build_bqn8c5oncbrv33jyn5ld7eddp$_run_closure3@2ec4a0f9]的test()方法。" - ildar ishalin
1
把你的代码展示在代码桶里,整个build.gradle文件。以上代码完全正常,你可能缺少了Java插件? - LazerBanana
1
我正在使用Android插件,这可能会有问题吗? - ildar ishalin

5
你需要在buildscript块之外添加一个repositories部分:
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()
}

1

很有帮助。对我有效的代码行是:apply plugin: org.junit.platform.gradle.plugin.JUnitPlatformPlugin - yname

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接