gradle - 如何在Gradle(不包括xz tar文件)中使用ant-compress?

标签 gradle ant

我想解压缩.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/

相关文章:

java - 如何指定 Google Guice 的实现路径?

java - xdoclet 与 xdoclet2?

java - Eclipse Luna Gradle插件添加了未引用的依赖项

android - Gradle 复制任务始终是最新的

带有 Gradle 的 Android(Java 以非零退出值 2 完成)

gradle - 使用 gradle scala 插件运行 Scala 测试

gradle - 如何深入了解 "implementation"配置的依赖关系?

ant - 重命名与移动 Ant 任务

java - 如何让 .jar 识别和使用捆绑的 log4j.xml 文件?

Maven ANT 项目