Using the war plugin with filter


I’m using the war plugin with a filter like so:

war {
        filter { it = it.replace('foo', 'bar') }
    duplicatesStrategy = 'EXCLUDE'

Unfortunately this only includes the pre-filtered files,
if I remove the duplicatesStrategy it includes both version but it leads to unwanted results,

Is there w way to only include the filtered files?


You could probably do something like this.

war {
    filesMatching('src/main/resources/**') { details ->
        details.filter { it.replace('foo', 'bar') }

This only includes the unfiltered file,
I need the file after processing to be included in the war

Ah yes, sorry. The WAR classpath (everything going into WEB-INF/classes) is treated a bit special. You’ll want to do the filtering as part of the ‘processResources’ task.

processResources {
    filter { it.replace('foo', 'bar') }