Why Is There Not An Unzip Task?

Unzipping at the moment is overly complicated

task unzip(type: Copy) {
    def zipFile = file('D:/external/dependent.war')
    def outputDir = file('lib')
      from zipTree(zipFile)
    into outputDir
    include 'WEB-INF/lib/*.jar'

Why would you think to use a Copy task when you want to unzip? I know that is fundamentally what happens when you unzip something but I don’t want to be exposed to that level.

ANT has had this for years https://ant.apache.org/manual/Tasks/unzip.html

<unzip src="${tomcat_src}/tools-src.zip" dest="${tools.home}"/>

I find it mind boggling that you have reached a second major release without this. Why don’t you just make an Unzip task that wraps the Copy task and hides the unnecessary internals?

Most of the time I just want to say source and destination and not have to do all the extra stuff that is currently required.

To be fair, your first example is unnecessarily verbose.

task unzip(type: Copy) {

from(zipTree(‘D:/external/dependent.war’)) { include ‘WEB-INF/lib/*.jar’ }

into ‘lib’


How would you imagine an “Unzip” task implemented? How would the task determine what sources of the CopySpec to unpack? For example, that war file contains jars (which are archives). I don’t think you could do this by extending the Copy task without breaking the interface contract defined by CopySpec. You’d probably have to create a whole new task, which wouldn’t be nearly as capable as the existing Copy task, only to trivially simplify this one use case.

As a (small) further simplification, the ‘include’ can stay at the top level here.

Extend the Copy task, name it Unzip then pass the from to the zipTree.

What else is there?

By doing so you have abstracted the inner workings away from the user and created a functional task that users will automatically think of when they want to unzip a file as part of their build.

1 Like