2017-10-19 100 views
2

在将org.junit.platform.gradle.plugin添加到构建中并从junit4迁移所有内容之后Gradle开始打破以下错误。JUnit5 Gradle插件的文件名或扩展名太长

所有运行良好的复古赛跑者,但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测试消费者应对这种事情呢?或者也许有一些超级jar处理这些?


EDIT1

我怀疑这可能是类路径,即时通讯将产生所有的JUnit模块的uberjar。


EDIT2

展望源代码看起来像Junit的插件添加加载到classpath

// 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库包装在一个artefact中的项目。


EDIT3

我没有管理的所有木星的文物打包成1缩小CP一点,但仍然是我的classpath越过35K这是一个有点怪异

如何那么gradle是否会运行junit5测试呢?似乎是它把所有其他相关项目的所有传递,并添加他们的CP,然后刹车错误= 206

回答

2

我已经设法使所有与下面的代码工作。

它将生成一个带有清单的jar,并将该jar放在classpath中。

它没有使用任何只是运行平台的插件作为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 

} 

另外,现在你可以使用这个插件它可以完成上述,只是它过长的类路径适用于该项目。

https://github.com/viswaramamoorthy/gradle-util-plugins

相关问题