Search code examples
gradlewargretty

How to perform same resource filtering for both gretty and war?


Here's a snippet of a Gradle build script that filters web.xml both when building a WAR and when running the webapp with gretty's appRun task. Is there a way to share a single 'filesMatching' definition instead of repeating it?

import org.apache.tools.ant.filters.ReplaceTokens

def tokens = [
        "foo": "bar",
]

war {
    filesMatching("WEB-INF/web.xml") {
        filter(ReplaceTokens, tokens: tokens)
    }
}

gretty {
    webappCopy {
        filesMatching 'WEB-INF/web.xml', {
            filter(ReplaceTokens, tokens: tokens)
        }
    }
}

Solution

  • According to the gretty documentation, any configuration added to webappCopy will be automatically added to war by the plugin.