我有一个包含中文foldername的Zipfile。
使用Linux unzip,Windows Winrar和7Zip
可以毫无问题地提取Zip文件使用Gradles“ziptree”时,我总是会收到以下错误:
Could not expand ZIP '/pathToZip/myZip.zip'.
Stacktrace说:
Caused by: org.gradle.api.GradleException: Could not copy zip entry /pathToZip/myZip.zip!somefolderstructure/??/ to '/destination/somefolderstructure/??'.
at org.gradle.api.internal.file.AbstractFileTreeElement.copyTo(AbstractFileTreeElement.java:79)
at org.gradle.api.internal.file.copy.DefaultFileCopyDetails.copyTo(DefaultFileCopyDetails.java:106)
at org.gradle.api.internal.file.copy.FileCopyAction$FileCopyDetailsInternalAction.processFile(FileCopyAction.java:44)
at org.gradle.api.internal.file.copy.SyncCopyActionDecorator$1$1.processFile(SyncCopyActionDecorator.java:59)
at org.gradle.api.internal.file.copy.NormalizingCopyActionDecorator$1.maybeVisit(NormalizingCopyActionDecorator.java:98)
at org.gradle.api.internal.file.copy.NormalizingCopyActionDecorator$1.access$000(NormalizingCopyActionDecorator.java:53)
at org.gradle.api.internal.file.copy.NormalizingCopyActionDecorator$1$1.processFile(NormalizingCopyActionDecorator.java:65)
at org.gradle.api.internal.file.copy.DuplicateHandlingCopyActionDecorator$1$1.processFile(DuplicateHandlingCopyActionDecorator.java:60)
at org.gradle.api.internal.file.copy.CopyFileVisitorImpl.processFile(CopyFileVisitorImpl.java:62)
at org.gradle.api.internal.file.copy.CopyFileVisitorImpl.visitFile(CopyFileVisitorImpl.java:46)
at org.gradle.api.internal.file.AbstractFileTree$FilteredFileTreeImpl$1.visitFile(AbstractFileTree.java:181)
at org.gradle.api.internal.file.archive.ZipFileTree.visit(ZipFileTree.java:91)
... 97 more
Caused by: org.gradle.internal.nativeintegration.filesystem.FileException: Could not set file mode 755 on '/destination/somefolderstructure/??'.
at org.gradle.internal.nativeintegration.filesystem.services.GenericFileSystem.chmod(GenericFileSystem.java:89)
at org.gradle.api.internal.file.AbstractFileTreeElement.copyTo(AbstractFileTreeElement.java:76)
... 108 more
Caused by: net.rubygrapefruit.platform.NativeException: Could not set UNIX mode on /destination/somefolderstructure/??: could not convert string to current locale
at net.rubygrapefruit.platform.internal.DefaultPosixFiles.setMode(DefaultPosixFiles.java:61)
at org.gradle.internal.nativeintegration.filesystem.services.NativePlatformBackedChmod.chmod(NativePlatformBackedChmod.java:33)
at org.gradle.internal.nativeintegration.filesystem.services.GenericFileSystem.chmod(GenericFileSystem.java:87)
... 109 more
我已经尝试在gradle.properties中设置文件编码
file.encoding=utf-8
我尝试添加Gradle参数
-Dfile.encoding=utf-8
我还尝试了不同的Gradle版本:3.4.1和2.14
没有任何作用。
更新
这是我的build.gradle(路径与堆栈跟踪不匹配,因为我手动修改了堆栈跟踪):
apply plugin: 'maven'
def defaultEncoding = 'UTF-8'
tasks.withType(AbstractCompile).each {
it.options.encoding = defaultEncoding
}
tasks.withType(GroovyCompile).each {
it.groovyOptions.encoding = defaultEncoding
}
configurations {
mydependencies
}
dependencies {
mydependencies 'my.group:my-artifact:1.0.0@zip'
}
task copyArtifact(type: Copy) {
from configurations.mydependencies
into "$buildDir/zip"
}
task extractZip(type: Sync) {
from zipTree("$buildDir/zip/my-artifact.zip")
into "$buildDir/xtract"
}
任何想法?
修改zip是最后一个解决方案。
答案 0 :(得分:0)
这个怎么样?您的-Dfile.encoding=UTF-8
本身就是gradle编码,但它不会影响编译编码。请在build.gradle
上使用此功能。
def defaultEncoding = 'UTF-8'
tasks.withType(AbstractCompile).each {
it.options.encoding = defaultEncoding
}
tasks.withType(GroovyCompile).each {
it.groovyOptions.encoding = defaultEncoding
}
答案 1 :(得分:0)
至于中文文件夹仅用于节点子模块(https://github.com/jfhbrook/node-ecstatic/tree/master/test/public/%E4%B8%AD%E6%96%87)的测试目的,我使用" exclude"来自我的复制任务:
task extractDependency(type: Copy) {
from zipTree( configurations.mydependencies )
into "$buildDir/xtract"
exclude "$parentFolder/npm/node_modules/http-server/node_modules/ecstatic/test/public/"
}