In this post we're going to show how to package a WAR (or JAR) and selectively exclude directories at Build Time. We have a private version of our NixMash Blog app and a public version which use different Resource directories. When we build our private NixmashBlog.war file we want to exclude the public resource folders.
We want to go from this in our project files
…to this in our WAR file. We want to remove the /static and /templates directories as well as the messages.properties file.
The Gradle Task
To make this happen we're going to create a simple task in our MVC Module build.gradle file.
Then when we package our WAR we run the task prior to our Spring Boot Gradle Plugin bootRepackage task.
$ gradle mvc:clean mvc:nixClean mvc:bootRepackage