将文件从一个Zip文件复制到另一个Zip文件中

nod*_*e42 4 gradle

我们正在努力从Maven迁移到Gradle.不幸的是,我们仍然需要处理几个War叠加.

作为一种解决方法,我试图将一个war文件的内容复制到另一个war文件中.

这是我到目前为止:

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'
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

什么时候into { zipTree (product)}是一个文件(如file ('tmp/whatever')),这工作正常.当指定另一个zip文件(目标war文件)时,它失败并显示错误:

使用toString()方法将类org.gradle.api.internal.file.collections.FileTreeAdapter转换为File已被弃用,并计划在Gradle 2.0中删除.请改用java.io.File,java.lang.String,java.net.URL或java.net.URI.

如果有人对此有具体建议,或者更好地"叠加"战争文件,我真的很感激!

nod*_*e42 5

在追逐几个不同的角度后,我最终得到了这个:

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/**'
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

基本上我只是包含产品中任何.war依赖项的过滤内容.作为标准战争任务的改变,依赖树保持清洁.到目前为止似乎对我们有用......