Java JUnit5 Gradle插件文件名或扩展名太长
在将Java JUnit5 Gradle插件文件名或扩展名太长,java,windows,gradle,junit,junit5,Java,Windows,Gradle,Junit,Junit5,在将org.junit.platform.gradle.plugin添加到构建中并从junit4迁移所有内容之后,gradle开始出现以下错误 vintage runner的所有运行都很好,但junit5测试则不然 * Exception is: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':server:junitPlatformTest'. Caused by: org.gradle.pro
org.junit.platform.gradle.plugin
添加到构建中并从junit4迁移所有内容之后,gradle开始出现以下错误
vintage runner的所有运行都很好,但junit5测试则不然
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':server:junitPlatformTest'.
Caused by: org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'C:\Program Files\Java\jdk1.8.0_131\bin\java.exe''
...
Caused by: java.io.IOException: CreateProcess error=206, The filename or extension is too long
我是否需要以某种方式配置junit5测试消费者来处理这类事情?或者可能有一些uber jar在处理这些问题?
EDIT1 我怀疑这可能是类路径,我将生成一个包含所有junit模块的uberjar
EDIT2 查看源代码看起来像是Junit插件向类路径添加了负载
// Note: the user's test runtime classpath must come first; otherwise, code
// instrumented by Clover in JUnit's build will be shadowed by JARs pulled in
// via the junitPlatform configuration... leading to zero code coverage for
// the respective modules.
classpath = project.sourceSets.test.runtimeClasspath + project.configurations.junitPlatform
我很好奇,在项目评估之后,我是否可以删除这个配置junitPlatform
,因为所有的JUnit依赖项都被添加到了要编译的代码中,那么插件只是在顶部添加了负载。我创建了一个项目,将所有Junit5库封装在一个人工制品中
EDIT3 我确实设法将所有的jupiter人工制品打包成1,以缩小cp,但我的类路径仍然超过35k,这有点奇怪
gradle是如何运行junit5测试的?似乎它将所有其他相关项目的所有转换放在一起,并将它们添加到cp中,然后cp会停止运行,错误=206gradle 4.6支持JUNIT 5强> 请记住,老式引擎需要与jupiter现在的版本相同 编辑日期:2018年3月16日
我已经设法使所有的工作与下面的代码 它将生成一个带有清单的jar,并将该jar放在类路径上 它没有使用任何插件,只是将平台作为javaExec任务运行 此文件需要应用于要在其上运行测试的项目
def version = "5.0.1"
def platformVersion = "1.0.1"
def vintageVersion = "4.12.1"
def projectCp = "${project.name}Classpath.jar"
dependencies {
compile "org.junit.jupiter:junit-jupiter-api:$version"
compile "org.junit.platform:junit-platform-launcher:$platformVersion"
compile "org.junit.platform:junit-platform-runner:$platformVersion"
testCompile "junit:junit:4.12"
testCompile "org.junit.jupiter:junit-jupiter-params:$version"
testRuntime "org.junit.vintage:junit-vintage-engine:$vintageVersion"
testRuntime "org.junit.platform:junit-platform-console:$platformVersion"
testRuntime "org.junit.jupiter:junit-jupiter-engine:$version"
}
afterEvaluate {
if (!project.tasks.findByName('packClasspath')) {
task packClasspath(type: Jar) {
archiveName = projectCp
version = ''
manifest {
attributes 'Class-Path':
project.configurations.testRuntime.collect { "file:///${it.absolutePath}" }.join(' ')}
}
}
if (!project.tasks.findByName('jupiterTest')) {
task jupiterTest(type: JavaExec) {
jvmArgs '-ea'
classpath = files(
"${project.buildDir}\\libs\\${projectCp}",
project.sourceSets.test.output,
project.sourceSets.main.output,
)
main 'org.junit.platform.console.ConsoleLauncher'
args '--scan-class-path'
args "--reports-dir=$project.testReportDir"
}
}
test.dependsOn jupiterTest
jupiterTest.dependsOn packClasspath
jupiterTest.dependsOn testClasses
test.enabled = false
}
或者,现在您可以使用这个插件来实现上述功能,只需将其应用于类路径过长的项目即可
编辑
Gradle4.6支持JUnit5强>