Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude a resource from the war file in Grails 2.0?

I have some test data with some special content (images, videos, etc.) in my Grails 2 application that should not be included when building the war. At development time, these files are stored in web-app/content/. So the question is, how do I exclude them when build a war for the production environment?

During my search I came accross this blog post, covering the topic in an earlier Grails version. Unfortunately it doesn't seem to work anymore and the comments didn't help me either.

This is what I have tried for now:

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

Maybe I am just missing something? Or is there even a better way to separate test-data from shipping the application?

like image 681
Roland Schneider Avatar asked Nov 30 '25 10:11

Roland Schneider


1 Answers

Yeah, I was obviously missing something. Or to be more precise sometimes less information is more. After a bit more of googling for ant delete fileset I saw that the includes attribute is deprecated. After leaving it out, all files in the content directory were removed. Even the directory structure is still present, which is exactly what I wanted.

So my solution for now is:

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

EDIT: As far as I know grails uses ant under the hood, so the Ant Delete Task is the thing to look at. So I guess if you want to delete the empty subdirectories too, it would be (not checked though):

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

or if u want to delete the content folder itself just:

delete(dir: "${stagingDir}/content/")
like image 199
Roland Schneider Avatar answered Dec 05 '25 09:12

Roland Schneider



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!