How to easily zip files without using Zip task?


because of some Zip & Copy tasks limitations, I need to zip files without using the Zip task.

I was wondering if it is somehow possible natively in Gradle (using FileTrees) in the same was as there is Copy task together with Project.copy() method.


What limitations are you finding?

The easiest thing to do is to fall back to the task:

See the javadoc here which states that the files(...) methods can accept a Closure if you need to delay the evaluation. I’m guessing you can use this in a Zip or Copy task and it will only be evaluated just in time


   FileCollection lazyFiles = files({
      FileTree allTree = files().asFileTree
      file('build/source.txt').readLines().each {
      return allTree
   task myCopy(type: Copy, dependsOn: generateSources) {
      from lazyFiles
      into 'foo' 

Hi Lance, late response here. FYI, in my case I am defining the zip task during applying of my plugin. And I get to know the basename of the zip later, during execution of the buildscript. setBaseName only accepts a plain string, so I cannot set it in a closure. The workaround is to call setBaseName on the task in a doFirst block. Another option is to do everything in a doLast and use