Copy files from one ZIP file to another in Gradle

We are working on migrating to Gradle from Maven. Unfortunately, we still have a couple of military issues that we have to deal with.

As a job, I am trying to copy the contents of one war file to another.

This is what I have so far:

task overlayWars (dependsOn: war) << { // Get the source war files to copy the contents from... def dependencyWars = configurations.runtime.filter { it.name.endsWith ('.war') } dependencyWars.each { dependentWar -> // Get the products, ie the target war file... war.outputs.files.each { product -> println "Copying $dependentWar contents into $product" copy { from { zipTree (dependentWar) } into { zipTree (product)} // this seems to be the problem include 'WEB-INF/classes/**/*.class' include 'WEB-INF/jsp/**/*.jsp' } } } } 

When into { zipTree (product)} is a file (for example, file ('tmp/whatever') ), this works fine. When specifying another zip file (target war file), it fails with an error:

Converting the org.gradle.api.internal.file.collections.FileTreeAdapter class to use files The toString () method is deprecated and must be removed in Gradle 2.0. Use java.io.File, java.lang.String, java.net.URL or java.net.URI.

If anyone has any suggestions on this, or the best way to โ€œoverlayโ€ military files, I would really appreciate it!

+4
source share
2 answers

After chasing several different angles, I ended up with this:

 war { configurations.runtime.filter { it.name.endsWith ('.war') }.each { from zipTree (it).matching { include 'WEB-INF/classes/**/*.class' include 'WEB-INF/jsp/**/*.jsp' include 'images/**' } } } 

Basically, I just include the filtered content of any .war dependencies in the product. Being a change to the standard military task, the dependency tree stays clean. It seems to work for us so far ...

+5
source

If you are trying to combine wars here, you cannot do this with the Copy task / method. You will need to use the Zip task (there is no equivalent method). If you want to unite in an existing war, the way to do this is existingWar.from { zipTree(otherWar) } .

+1
source

Source: https://habr.com/ru/post/1493294/


All Articles