[英]JUnit5 Gradle plugin the filename or extension is too long
After adding org.junit.platform.gradle.plugin
into the build and migrating everything from junit4 Gradle started to break with below error. 将
org.junit.platform.gradle.plugin
添加到构建中并从junit4 Gradle开始迁移所有内容后突破以下错误。
All runs fine with the vintage runner but junit5 tests are not. 一切都与老式跑步者一样好,但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
Do I need to configure the junit5 test consumer somehow to deal with this sort of things? 我是否需要以某种方式配置junit5测试消费者来处理这类事情? or maybe there is some uber jar handling those?
或者也许有一些超级罐处理那些?
EDIT1 EDIT1
I have a suspicion this might be the classpath, im going to generate an uberjar with all junit modules. 我怀疑这可能是类路径,我将使用所有junit模块生成一个uberjar。
EDIT2 EDIT2
Looking into the source code seems like Junit plugin adds loads to the classpath 查看源代码似乎是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
Im curious if I could wipe out this configuration junitPlatform
after the project evaluate as all JUnit dependencies are added anyway for the code to compile, then the plugin is just adding loads on the top. 我很好奇,如果我可以在项目评估之后消除这个配置
junitPlatform
,因为无论如何都要为编译代码添加所有JUnit依赖项,那么插件只是在顶部添加负载。 And I created a project that wraps all Junit5 libs inside one artefact. 我创建了一个项目,将所有Junit5库包装在一个人工制品中。
EDIT3 EDIT3
I did manage to pack up all jupiter artefacts into 1 to shrink the cp a little, but still my classpath goes over 35k which is a bit weird 我确实设法将所有木星文物打包成1以缩小cp,但我的类路径仍超过35k这有点奇怪
How does gradle run junit5 tests then? gradle如何运行junit5测试呢? seems like it puts all transitives from all other projects related, and adds them the cp, which then brakes with error=206
似乎它将所有其他项目的所有传递都相关联,并将它们添加到cp中,然后使用error = 206进行制动
GRADLE 4.6 SUPPORTS JUNIT 5! GRADLE 4.6支持JUNIT 5! Remember that vintage engine need to be same version as the jupiter now Edited: 16/03/2018
请记住,老式引擎需要与现在的木星版本相同编辑:16/03/2018
I have managed to make it all working with below code. 我已设法使用以下代码完成所有工作。
it is going to produce a jar with a manifest and put that jar on the classpath. 它将生成一个带有清单的jar并将该jar放在类路径上。
It's not using any plugins just running the platform as a javaExec task. 它没有使用任何仅作为javaExec任务运行平台的插件。
This file needs to be applied to the project you want to run your test on. 此文件需要应用于要运行测试的项目。
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
}
Alternatively, now you can use this plugin which does the above, just apply it to the project with too long classpath. 或者,现在您可以使用此插件执行上述操作,只需将其应用于具有太长类路径的项目。
https://github.com/viswaramamoorthy/gradle-util-plugins https://github.com/viswaramamoorthy/gradle-util-plugins
Edit 编辑
GRADLE 4.6 SUPPORTS JUNIT 5! GRADLE 4.6支持JUNIT 5!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.