如何在Gradle中将文件从JAR复制到WAR?

时间:2013-10-03 18:54:20

标签: jar resources copy gradle war

我需要使用Gradle将JAR中的特定文件复制到WAR中的特定目录中。 我的代码:

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
                }
            }
        }
    }

问题:“dest”值不正确,而不是在创建的WAR文件中,它类似于“libs / mywar-1.0.war / destinationFolder”。

1 个答案:

答案 0 :(得分:1)

你会想要这样的东西:

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