问题描述
对于gradle,有几种解决Windows路径太长的问题的解决方案:
A couple of solutions to the problem of the windows path being too long are present for gradle:
- Add classpath in manifest using Gradle
- "The filename or extension is too long error" using gradle
但是,我不清楚如何在多项目设置中处理此问题.具有application
插件的所有子项目是否都需要这些更改?还能在init.gradle
文件中指定吗?
However, it is unclear to me how to handle this in a multi project setup. Would all sub-projects with the application
plugin require these changes?Could this also be specified in the init.gradle
file?
还有更好的解决方法吗?
Also is there a better workaround?
显然 https://github.com/viswaramamoorthy/gradle-util-plugins/已发布.但是,它不能为我解决问题.最初的Java问题已解决-但无法正确解决.某些类无法再加载,即在出现scala时执行单元测试.
Apparently https://github.com/viswaramamoorthy/gradle-util-plugins/ has been published. However, it does not fix the problems for me. The initial java problem is solved - but not correctly. Some classes can no longer be loaded i.e. unit tests be executed in case of 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
期间失败,因为在几个链接中报告的清单技巧似乎与scala有关:
unfortunately fails with during shadowJar
as the manifest tricks reported in several of the links seem to have a problem with 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
即使从未创建此文件
再尝试一件事:一个包含所有测试用例的胖子罐:
trying one more thing: a fat jar including all the test cases:
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 是解决方案的下一步.
from https://github.com/maiflai/gradle-scalatest/issues/63 is the next step towards a solution.
这篇关于gradle windows java.io.IOException:CreateProcess错误= 206,文件名太长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!