distZip task produces incorrect Zip files with doubled entries

startScripts {
  inputs.property("classpath", { classpath }) // for incremental build to work properly
  outputs.dir "$buildDir/scripts"
  classpath += files('src/main/config')
  //workaround for gradle bug paths must be manually corrected
  doLast {
    def windowsScriptFile = file getWindowsScript()
    def unixScriptFile = file getUnixScript()
    String text = windowsScriptFile.text
    String textTmp = ""
    text.readLines().each {
      line ->
        if (regExp.matcher(line).find()) {
          textTmp += line + "\n\n@rem Change folder to application home\ncd %APP_HOME%\n"
        } else {
          textTmp += line + '\n'
        }
    }
      windowsScriptFile.text = textTmp
    windowsScriptFile.text = windowsScriptFile.text.replace("%APP_HOME%\lib\config", "%APP_HOME%\config")
    unixScriptFile.text = unixScriptFile.text.replace('$APP_HOME/lib/config', '$APP_HOME/config')
  }
}

No errors detected in compressed data of C:\Users\cwpl-zsokolow\Downloads\capella-1.0.51.20121217-141619.zip. Testing … It produces wrong zip file with doubled entries out put from winzip:

testing: capella-1.0.51.20121217-141619\bin\capella

OK testing: capella-1.0.51.20121217-141619\bin\capella.bat

OK testing: capella-1.0.51.20121217-141619\bin\capella

OK testing: capella-1.0.51.20121217-141619\bin\capella.bat

OK

but still there are warnings, is it a bug while a zip file is created?

Did you make any customizations to the distZip task itself? If yes, can you share it?. My first guess is that you accidently declare the startscripts files twice to be included in the distZip.

cheers, René

No I checked it twice. I have only once declared startScripts and I didn’t make any customizations to distZip (from code).

Cheers, Zbyszek

Somehow, your code is adding the same files twice - otherwise, a ‘Zip’ task won’t produce duplicate entries. Can you provide a self-contained, reproducible example?

I have noticed also that it has included twice a one jar. I can send you Peter a script I don’t want to copy - paste whole here. But this particular is not so complicated. Stupid question do you put name of files which should be zipped in set collection before zipping?

Cheers, Zbyszek

Are you asking if Gradle does that, or if I do it when authoring a Gradle build?

I’m just interested why it happens. I think that it should be impossible for user to add more than one file to zip. When user uses just a plugin without any customizations. I can imagine that customization could spoil something.

I’m just interested why it happens.

There’s probably some problem with your workaround.

I think that it should be impossible for user to add more than one file to zip.

It must be possible for users to add duplicate entries to archives, because there are valid use cases for this. However, there should be an easy way to ignore duplicates, and maybe duplicates should be ignored by default (however that would be a breaking change). If you are interested in where we are going with this, you can follow the design spec.

Guys, maybe you should add a simple property like: keepDuplicates?

Rene, for sure I don’t have two startScripts sections. This above is only one my section. Something is wrong with creating zip maybe when I’m using doLast? and something goes wrong