Gradle task to create a zip archive of a directory

Praveen picture Praveen · Apr 26, 2016 · Viewed 45k times · Source

I have a gradle task to create a zip archive of a directory. The gradle task is:

task archiveReports(type: Zip) {
   from '/projects/Reports/*'
   archiveName 'Reports.zip'
}

When I am running the command 'gradle archiveReports', its showing the build is successful. However, no zip file is getting created.

Am I missing something here?

Answer

Praveen picture Praveen · Apr 27, 2016

I figured out a way for this: Its working for me now.

task myZip(type: Zip) {
   from 'Reports/'
   include '*'
   include '*/*' //to include contents of a folder present inside Reports directory
   archiveName 'Reports.zip'
   destinationDir(file('/dir1/dir2/dir3/'))
}