Search code examples
gradleunzipunpack

Is possible to unzip multiple WARs from different repositories in a similar destination?


Using Gradle I try to unzip multiple WARs from different local repositories into the same destination but I cannot find a way.

According to several solutions using zipTree(object), I did something like....

task unpackingWar(type:Copy){ 
   destinationDir = file("$buildDir/generated-resources/unpack/static") 
   includes = ["**","*.jsp"] 
   includeEmptyDirs = false  
  for (webWar in configurations.webWarUnpacking.files){
       from{
          zipTree(webWar) 
      } 
}

The point is this solution is always overwritting the destination directory with last WAR of configuration list. I would like to unpack the whole list of WARs into the destination directory.

I thought in creating a ZIP with all WARs and unpacking them but I wanted to develop a more elegant way.


Solution

  • Finally I found a way using ant.unzip(), worked for me.

    tasks.register('unpackWar') {
    doLast {
        mkdir("build/generated-reources/unpack/static")
        for( webWar in configurations.webWarUnpacking.files) {
            ant.unzip(src: webWar, dest:"build/generated-reources/unpack/static", overwrite:"false") {
                patternset( ) {
                    include( name: '**' )
                    exclude( name: '**/*.jsp')
                }
                mapper(type:"identity")
            }
        }
    }
    

    }