簡體   English   中英

如何在 Gradle 中使用 ant-compress(解壓縮 xz tar 文件)?

[英]How do I use ant-compress within Gradle (untar an xz tar file)?

我想解壓一個.tar.xz格式的文件。 Gradle 的tarTree()不支持這種格式,所以我需要將.xz解壓縮到.tar ,然后我才能使用它。

根據文檔,我應該能夠做這樣的事情:

    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 回答討論了在 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

這是我的解決方案,涉及命令行實用程序。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM