我想解压缩.tar.xz
格式的文件。 Gradle的tarTree()
不支持此格式,因此我需要将.xz
解压缩为.tar
,然后才能使用它。
根据docs,我应该能够做这样的事情:
ant.untar(src: myTarFile, compression: "xz", dest: extractDir)
但是,我得到一个错误:
Caused by: : xz is not a legal value for this attribute
at org.apache.tools.ant.types.EnumeratedAttribute.setValue(EnumeratedAttribute.java:94)
此SO answer讨论在Maven中使用Apache Ant Compress antlib的问题。如何使用Gradle获得相似的结果?
最佳答案
在您的链接中转换Maven SO答案将类似于:
configurations {
antCompress
}
dependencies {
antCompress 'org.apache.ant:ant-compress:1.4'
}
task untar {
ext {
xzFile = file('path/to/file.xz')
outDir = "$buildDir/untar"
}
inputs.file xzFile
outputs.dir outDir
doLast {
ant.taskdef(
resource:"org/apache/ant/compress/antlib.xml"
classpath: configurations.antCompress.asPath
)
ant.unxz(src:xzFile.absolutePath, dest:"$buildDir/unxz.tar" )
copy {
from tarTree("$buildDir/unxz.tar")
into outDir
}
}
}
参见https://docs.gradle.org/current/userguide/ant.html
关于gradle - 如何在Gradle(不包括xz tar文件)中使用ant-compress?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60374815/