java - gradle windows java.io.IOException : CreateProcess error=206, 文件名太长

标签 java windows scala gradle cmd

gradle针对windows路径过长的问题提供了几种解决方案:

但是,我不清楚如何在多项目设置中处理这个问题。所有带有 application 插件的子项目都需要这些更改吗? 这也可以在 init.gradle 文件中指定吗?

还有更好的解决方法吗?

显然https://github.com/viswaramamoorthy/gradle-util-plugins/已发布。但是,它并不能解决我的问题。最初的 java 问题已解决 - 但不正确。某些类无法再加载,即在 scala 中无法执行单元测试。

编辑

experimenting with
task testPathingJar(type: Jar) {
        appendix = "testPathing"
        doFirst {
            manifest {
            attributes "Class-Path": configurations.testCompile.files.join(" ")
            }
        }
    }

    compileTestScala {
        dependsOn(testPathingJar)
        classpath = files(testPathingJar.archivePath)
    }    

    task pathingJar(type: Jar) {
        appendix = "pathing"
        doFirst {
            manifest {
            attributes "Class-Path": configurations.compile.files.join(" ")
            }
        }
    }

    compileScala {
        dependsOn(pathingJar)
        classpath = files(pathingJar.archivePath)
    }    

    build {
        dependsOn pathingJar
        doFirst {
            classpath = files("$buildDir/classes/main", "$buildDir/resources/main", pathingJar.archivePath)
        }
    }

不幸的是,在 shadowJar 期间失败,因为几个链接中报告的 list 技巧似乎与 scala 有问题:

Cannot infer Scala class path because no Scala library Jar was found. Does project ':tma-mobility-frequencyCounting' declare dependency to scala-library? Searched classpath: file collection.

尝试:

    jar {
      manifest {
        attributes(
          "Class-Path": configurations.compileOnly.collect { it.getName() }.join(' '))
      }
    }
fails for task `shadowDistZip` when executing `gradle build` with:

    java.io.IOException: Cannot run program "C:\Program Files\Java\jdk1.8.0_131\bin\java.exe" (in directory "D:\users\username\development\projects\projectName\Code\spark\module_name"): CreateProcess error=206, Der Dateiname oder die Erweiterung ist zu lang

moving gradle user home to the root (also the project) of the partition:

    .\gradlew.bat build --gradle-user-home D:\projects\gradleHome
fails with the same error for task `test`.

When trying the strategy of https://github.com/jhipster/generator-jhipster/pull/4324/files like:

task pathingJar(type: Jar) {
    dependsOn configurations.runtime
    appendix = 'pathing'

    doFirst {
        manifest {
            attributes 'Class-Path': configurations.runtime.files.collect {
                it.toURL().toString().replaceFirst(/file:\/+/, '/')
            }.join(' ')
        }
    }
}

build {
    dependsOn pathingJar
    doFirst {
        classpath = files("$buildDir/classes/main", "$buildDir/resources/main", pathingJar.archivePath)        }
}

task pathingJarTest(type: Jar) {
    dependsOn configurations.runtime
    appendix = 'pathing'

    doFirst {
        manifest {
            attributes 'Class-Path': configurations.runtime.files.collect {
                it.toURL().toString().replaceFirst(/file:\/+/, '/')
            }.join(' ')
        }
    }
}

test {
    dependsOn pathingJarTest
    doFirst {
        classpath = files("$buildDir/classes/main", "$buildDir/resources/main", pathingJarTest.archivePath)        }
}

失败

Caused by: org.gradle.api.GradleException: There were failing tests. See the report at: file:///C:/tmp/projectName/moduleName/reports/tests/test/index.html

即使这个文件从未被创建

再尝试一件事:一个包含所有测试用例的 fat jar 子:

task fatTestJar(type: Jar) {
    baseName = project.name + '-test-all'
    from {
        from { configurations.testRuntime.collect { it.isDirectory() ? it : zipTree(it) }}
        from sourceSets.test.output
    }
    with jar
}

但是,这尚未编译。

最佳答案

test {
  doFirst {
    def cp = CollectionUtils.join(File.pathSeparator, classpath.getFiles())
    environment 'CLASSPATH', cp
    classpath = classpath.filter { false }
  }
}

来自https://github.com/maiflai/gradle-scalatest/issues/63是解决方案的下一步。

关于java - gradle windows java.io.IOException : CreateProcess error=206, 文件名太长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50707110/

相关文章:

java - 如何从维基百科中提取标题标题和相应的文本

java - 如何在 Spark Java 中创建复杂的 StructType 架构

windows - 获取未知文件名以批量压缩文件

java - 在 Android 中集中列名

java - 调用removeAllViews();仍然导致 IllegalStateException :You must call removeView() on the child's parent first

windows - 适用于 Windows 的 Msysgit - Cheetah 插件未显示?

c - Windows系统编程

java - Scala 中的 "eval"

scala - 在Docker中使用WebJars进行SBT增量编译

scala - 为什么递归惰性列表会破坏 Scala 中的堆栈?