We are in the middle of transitioning from a rather large Maven build, and because of this, I need to do filtering on some resources containing the ${property} kind of place holders. In previous gradle builds, I have always used camel case properties, but as I can’t change the way Maven is set up, I am forced to use properties in the form of multi.level.property, i.e. with dots in them. Because of this, I use the Ant ExpandProperties filter.
The problem is that ExpandProperties doesn’t seem to handle UTF-8 very well. Files that are filtered get corrupted if they use non-ascii characters.
I have the following build.gradle:
import org.apache.tools.ant.filters.ExpandProperties
apply plugin: 'java'
processResources {
project.properties.each() { k, v ->
if (v != null) {
ant.properties[k] = v
}
}
filter(ExpandProperties, project: ant.project)
}
And the following file in src/main/resources/test.txt:
Try “this”.
Note the curly quotes in the resource file. This file actually doesn’t contain any placeholders, but that’s just because I’ve simplified the example as much as I can.
When I look at the resulting test.txt inside the build jar, it looks like this:
Try “thisâ?.
So the curly end quote has not been handled correctly during filtering. If I don’t use the ExpandProperties filtering, the file is copied correctly, so I assume it is a problem with the Ant filter. Is this a known limitation/bug in the Ant filter, and does anyone have an idea how to get around it?