简体   繁体   中英

How to copy files from JARs to WAR in Gradle?

I need to copy specific files that are in JARs into specific directory in WAR, using Gradle. My code:

war.doFirst {
    for(file in classpath) {
        FileTree tree = zipTree(file)
        FileTree treeResources = tree.matching { include "META-INF/resources/*" }

        String folderName = 'destinationFolder'
        {
            treeResources.each { 
                File resources -> copy {
                    from resources
                    String dest = war.destinationDir.name + "/" + war.archiveName + "/" + folderName
                    into dest
                }
            }
        }
    }

Problem: the "dest" value is incorrect, instead of being in the created WAR file, it is something like "libs/mywar-1.0.war/destinationFolder".

You'll want something like:

war {
    into("destinationFolder") {
        from { classpath.collect { zipTree(it) } }
        include "META-INF/resources/**"
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM