Unzip Archive with Groovy

前端 未结 9 1207
深忆病人
深忆病人 2020-12-15 04:00

is there a built-in support in Groovy to handle Zip files (the groovy way)?

Or do i have to use Java\'s java.util.zip.ZipFile to process Zip files in Groovy ?

9条回答
  •  攒了一身酷
    2020-12-15 04:37

    Although taking the question a bit into another direction, I started off using Groovy for a DSL that I was building, but ended up using Gradle as a starting point to better handle a lot of the file-based tasks that I wanted to do (eg., unzip and untar files, execute other programs, etc). Gradle builds on what groovy can do, and can be extended further via plugins.

    // build.gradle
    task doUnTar << {
        copy {
            // tarTree uses file ext to guess compression, or may be specific
            from tarTree(resources.gzip('foo.tar.gz'))
            into getBuildDir()
        }
    }
    
    task doUnZip << {
        copy {
            from zipTree('bar.zip')
            into getBuildDir()
        }
    }
    

    Then, for example (this extracts the bar.zip and foo.tgz into the directory build):

    $ gradle doUnZip
    $ gradle doUnTar
    

提交回复
热议问题