Trouble Filtering Resources

I’m new to Gradle so I don’t know if I’m doing something wrong or if this is a bug.

Using the examples in the Gradle User Guide, section 16.6.2, Filtering Files (, I’ve run into a couple of issues.

  1. Filtering files using ReplaceToken() works correctly on text files, but corrupts binary files.
  2. Filtering using expand() fails with an exception.

I’ve created an example project to show the behavior. Unfortunately, as a new user, I’m not allowed to upload it.


Hi Tim,

You could maybe use a code sharing service such as Github?

**EDIT - I have just found the ant docs for the copy task and theres a clear message about filtering binaries:

Note: If you employ filters in your copy operation, you should limit the copy to text files. Binary files will be corrupted by the copy operation. This applies whether the filters are implicitly defined by the filter task or explicitly provided to the copy operation as filtersets. See encoding note.

**EDIT **EDIT - Gradle uses the Ant implementation for ReplaceToken()

I’ve uploaded my example project to .


I just saw the edit to your reply.

I will try to figure out how to run processResources using two sources: one filtered and the other not filtered.

In the meantime, please look at the example project to help me with expand() and the other minor issues.


You can use CopySpec.eachFile { } to accomplish this.

processResources {
    eachFile { details -> 
        if ('.properties') {
            details.filter(ReplaceTokens, tokens: [foo: 'bar'])

Thanks for the info. I’ll see how I can use your suggestion in my project.