grailsgradlebuild.gradlegrails-3.1

Excluding files/directories from WAR packaging in Grails 3


In my Grails 3.1.10 app, I have a few files in src/main/webapp/ng directory for an Angular app and I want to exclude few of the directories/files from packaging to the WAR file at the time of grails package command.

In Grails 2.x app, we have achieved it via BuildConfig.groovy setting:

grails.war.resources = { stagingDir, args ->
    delete(dir: "${stagingDir}/ng/node_modules")
    delete(dir: "${stagingDir}/ng/app")
    delete(dir: "${stagingDir}/ng/bower_components")
}

How can we achieve that in Grails 3? I tried searching for it but didn't find anything.


Solution

  • I realized later that Grails 3 is using Gradle and Grails 2 was using Ant task. So I searched the same issue of excluding stuff in Gradle since Grails 3 uses Gradle's WAR plugin and from the docs:

    Of course one can configure the different file-sets with a closure to define excludes and includes.

    Here is the solution to exclude files in Grails 3 from packaging.

    Put the following in the build.gradle file of your Grails 3 application:

    war {
        exclude("ng/node_modules")
        exclude("ng/bower_components")
        exclude("ng/app")
        exclude("ng/*.tar.gz")
        exclude("ng/.*")       // For example: exclude all the hidden files
    }