我正在尝试使用gradle解压缩tar.xz
文件。首先我下载它,然后使用任务解压缩
def rootDir = project(":").projectDir
task downloadGHC(type: Download) {
src "$ghcDownloadLink"
dest new File("$rootDir/applications/install", "ghc-8.0.1-x86_64-unknown-mingw32.tar.xz")
onlyIfNewer true
}
task unpackGHC(dependsOn: downloadGHC, type: Copy) {
from tarTree(downloadGHC.dest)
into "$rootDir/applications/ghc"
}
但是我收到了这个错误
Unable to expand TAR 'L:\...\applications\install\ghc-8.0.1-x86_64-unknown-mingw32.tar.xz'
The tar might be corrupted or it is compressed in an unexpected way.
By default the tar tree tries to guess the compression based on the file extension.
If you need to specify the compression explicitly please refer to the DSL reference.
> Error detected parsing the header
我可以打开文件,因此它没有损坏。如何打开包装?
答案 0 :(得分:1)
由于解析标头时出错,我认为tarTree()
仅接受.tar
个文件,而不接受.tar.xz
个文件。您可以从gradle脚本中调用tar
之类的外部程序来解压缩文件
或者你可以编写一个小程序,使用xz-java库(XZInputStream类)将xz解压缩到tar。