Zip directory to multiple destinations using Gradle

Tags: , , ,



Is it possible with Gradle’s Zip task to copy the resulting zip into multiple destinations?

AFAIK you can only zip multiple input directories with only one output destination. Is there a way to zip a directory and copy the archive to multiple destinations (in one single task)? Since I’m bound to using Gradle v5.0, a solution for that version of Gradle would be highly appreciated.

Answer

The internal action of Zip tasks will only output the zip file to a single directory. If you don’t want create additional Copy tasks, you may use a doLast closure and use the method copy provided by the Project instance.

task myZip(type: Zip) {
    ...
    doLast {
        copy {
            from archivePath
            into 'path/to/other/destination'
        }
    } 
} 


Source: stackoverflow