【问题标题】:JUnit5 Gradle plugin the filename or extension is too longJUnit5 Gradle 插件文件名或扩展名太长
【发布时间】:2017-10-19 09:54:47
【问题描述】:

org.junit.platform.gradle.plugin 添加到构建中并从junit4 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 测试使用者来处理这类事情?或者也许有一些 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 artefacts 打包成 1 以稍微缩小 cp,但我的类路径仍然超过 35k,这有点奇怪

那么 gradle 是如何运行 junit5 测试的呢? 似乎它将所有其他相关项目的所有传递性都放入其中,并将它们添加到 cp,然后以 error=206 停止

【问题讨论】:

    标签: java windows gradle junit junit5


    【解决方案1】:

    GRADLE 4.6 支持 JUNIT 5! 请记住,老式引擎现在需要与木星的版本相同 编辑:16/03/2018


    我已经设法使这一切都使用下面的代码。

    它将生成一个带有清单的 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
    
    }
    

    或者,现在您可以使用执行上述操作的插件,只需将其应用于类路径过长的项目即可。

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

    编辑

    GRADLE 4.6 支持 JUNIT 5!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-21
      • 1970-01-01
      • 2012-02-09
      • 1970-01-01
      • 2019-08-19
      相关资源
      最近更新 更多