Copying Files From One Zip File Into Another In Gradle
gradle
Solution
After chasing down a couple of 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 am just including filtered contents of any .war dependencies in the product. Being an alteration to the standard war task, the dependency tree is kept clean. It seems to work for us so far...
Problem
We are working on migrating to Gradle from Maven. Unfortunately we still have a couple of War overlays to deal with. As a work-around I am trying to copy the contents of one war file into 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 (like `file ('tmp/whatever')`) this works fine. When specifying another zip file (the target war file) it fails with the error: Converting class org.gradle.api.internal.file.collections.FileTreeAdapter to File using toString() method has been deprecated and is scheduled to be removed in Gradle 2.0. Please use java.io.File, java.lang.String, java.net.URL, or java.net.URI instead. If anyone has suggestions on this specifically, or a better way to "overlay" war files, I'd really appreciate it!