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 (http://gradle.org/docs/current/userguide/working_with_files.html#sec:copying_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.

Thanks,
Tim

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 http://www.filedroper.com/foo .

Thanks,
Tim

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.

Thanks,
Tim

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

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

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