我如何在 Gradle(untar 一个 xz tar 文件)中使用 ant-compress?
How do I use ant-compress within Gradle (untar an xz tar file)?
我想解压 .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?
获得类似的结果
在您的 link 中转换 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
}
}
}
这是我的涉及命令行实用程序的解决方案。
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")
}
}
}
我想解压 .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?
获得类似的结果在您的 link 中转换 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
}
}
}
这是我的涉及命令行实用程序的解决方案。
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")
}
}
}