2017-09-28 56 views
4

嘗試使用JUnit 5 gradle這個:Junit的5 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' 
... 

錯誤:

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

搖籃4.0版。哪裏不對?

+0

這一切看起來不錯。配置看起來很好。你有沒有與互聯網連接/代理設置有任何問題? – Opal

+0

互聯網正常工作 – Sunnyday

+0

您可以添加'--stacktrace'來構建參數併發布它嗎? – mkobit

回答

3

你必須包括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 from: ...主要build.gradle?如果是這樣,你可能會遇到Gradle中的一個插件ID無法在外部腳本中使用的bug。相反,您必須指定完全限定的類名稱。

更多信息:

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

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

+0

這有幫助。爲我工作的那一行:'apply plugin:org.junit.platform.gradle.plugin.JUnitPlatformPlugin' – yname

0

從版本4.6 搖籃,就沒有必要再插件

搖籃支持Junit5本身只是做:

dependencies { 
    test.useJUnitPlatform() 

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