distZip task produces incorrect Zip files with doubled entries

(Zbyszek Sokolowski) #1
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- Testing … It produces wrong zip file with doubled entries out put from winzip:

testing: capella-\bin\capella

OK testing: capella-\bin\capella.bat

OK testing: capella-\bin\capella

OK testing: capella-\bin\capella.bat


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

Two of the same jars when using distZip
(René Groeschke) #2

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é

(Zbyszek Sokolowski) #3

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

Cheers, Zbyszek

(Peter Niederwieser) #4

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?

(Zbyszek Sokolowski) #5

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

(Peter Niederwieser) #6

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

(Zbyszek Sokolowski) #7

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.

(Peter Niederwieser) #8

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.

(Zbyszek Sokolowski) #9

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

(Zbyszek Sokolowski) #10

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