rjsang
rjsang

Reputation: 1757

How do I build a war file with Gradle using a copySpec containing filesMatching

So, this works:

war {
    filesMatching('**/index.jsp') {
        filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [
          'version' : version,
        ])
    }
}

But this does not:

def webappFilter = project.copySpec {
    filesMatching('**/index.jsp') {
        filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [
          'version' : version,
        ])
    }
}

war {
    with webappFilter
}

Obviously, I'm doing it wrong, but I can't understand what exactly it is that I'm missing. Can anyone help?

Upvotes: 3

Views: 884

Answers (1)

Lars
Lars

Reputation: 56

I had similar problems with copySpecs Gradle just not using them. After having tried out many variants it only worked for me when adding a copy closure to the copySpec.

def cs = copySpec {
    copy {
        from("readme.txt")
        into("somefolder")
        filter{String line -> line.replaceAll('a','b')}
    }
}   

task mycopy (type: Copy) {
    with cs 
} 

Hope this helps.

Upvotes: 2

Related Questions