如何从Grails 2.0中的war文件中排除资源?

时间:2011-12-19 16:58:40

标签: grails build resources

我的Grails 2应用程序中有一些特殊内容(图像,视频等)的测试数据,在构建战争时不应包含这些内容。在开发时,这些文件存储在web-app/content/中。所以问题是,在为生产环境构建战争时如何排除它们?

在我的搜索过程中,我遇到了this blog post, covering the topic in an earlier Grails version。不幸的是它似乎不再起作用了,评论也没有帮助我。

这就是我现在所尝试的:

grails.war.resources = { stagingDir ->
    delete { fileset(dir: "${stagingDir}/content/", includes: '*') }
}

也许我只是错过了一些东西?或者是否有更好的方法将测试数据与运送应用程序分开?

1 个答案:

答案 0 :(得分:7)

是的,我显然错过了一些东西。或者更确切地说,有时候信息越少越好。在对ant delete fileset进行了一次Google搜索后,我发现includes属性已被弃用。将其删除后,content目录中的所有文件都被删除了。甚至目录结构仍然存在,这正是我想要的。

所以我现在的解决方案是:

grails.war.resources = { stagingDir ->
    delete { fileset dir: "${stagingDir}/content/" }
}

编辑: 据我所知,grails在引擎盖下使用了蚂蚁,所以Ant Delete Task是值得关注的。所以我想如果你想删除空的子目录,它也会(虽然没有检查):

delete(includeEmptyDirs: true) { fileset dir: "${stagingDir}/content/" }

或者如果你想删除content文件夹本身:

delete(dir: "${stagingDir}/content/")