[英]How do I use ant-compress within Gradle (untar an xz tar file)?
I want to untar a file that is in .tar.xz
format.我想解压一个.tar.xz
格式的文件。 Gradle's tarTree()
does not support this format, so I need to unzip the .xz
to a .tar
, then I can make use of it. Gradle 的tarTree()
不支持这种格式,所以我需要将.xz
解压缩到.tar
,然后我才能使用它。
According to the docs , i should be able to do something like this:根据文档,我应该能够做这样的事情:
ant.untar(src: myTarFile, compression: "xz", dest: extractDir)
However, I get an error:但是,我收到一个错误:
Caused by: : xz is not a legal value for this attribute
at org.apache.tools.ant.types.EnumeratedAttribute.setValue(EnumeratedAttribute.java:94)
This SO answer talks about using the Apache Ant Compress antlib within Maven.这个SO 回答讨论了在 Maven 中使用 Apache Ant Compress antlib。 How can I achieve a similar result using Gradle?如何使用 Gradle 获得类似的结果?
Converting the Maven SO answer in your link would be something like:在您的链接中转换 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
}
}
}
See https://docs.gradle.org/current/userguide/ant.html见https://docs.gradle.org/current/userguide/ant.html
Here's my solution that involves command line utilities.这是我的解决方案,涉及命令行实用程序。
task untar() {
inputs.property('archiveFile', 'path/to/file.xz')
inputs.property('dest', 'path/to/file.xz')
outputs.dir("${buildDir}/destination")
doLast {
mkdir("${buildDir}/destination")
exec {
commandLine('tar', 'xJf', inputs.properties.archiveFile, '-C', "${buildDir}/destination")
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.