Problem with Zip task when source and destination directories are the same

Given the following task:

task zipit (type: Zip) {

from buildDir

destinationDir buildDir

baseName ‘output’

version ‘1.0’

}

The generated .zip file contains another .zip file of the same name. However, the nested .zip file is not a valid .zip file. I take it that the Zip task follows the following algorithm:

  1. Create an appropriately named .zip file in the ‘destinationDir’ 2. Enumerate the sources 3. Stuff the .zip file with the sources

I can get around this by adding an ‘exclude’ parameter like:

task zipit (type: Zip) {

from buildDir

destinationDir buildDir

exclude ‘output*.zip’

baseName ‘output’

version ‘1.0’

}

But I feel like the algorithm is broken and should be this instead:

  1. Enumerate the sources 2. Create an appropriately named .zip file in the ‘destinationDir’ 3. Stuff the .zip file with the sources

Hopefully no one is relying on this odd behavior. Does it sound like a bug to you guys?

The problem with this approach is that it would be slower and memory intensive, and there’s only a benefit in the fringe case that you find yourself in. So, everyone pays the cost and few benefit.