Issue using FileWriter with UTF-8

I have a java test that writes an hardcoded utf string to a file using FileWriter

when using

tasks.withType(JavaCompile) {

options.encoding = “UTF-8”

} OR gradle.properties: systemProp.file.encoding=utf-8

the file is NOT written correctly

the only thing that works is running gradle with a vm option: -Dfile.encoding=utf-8

<code>
tasks.withType(JavaCompile) { 
options.encoding = “UTF-8” 

</code>

Will specify what charset the source files are written in, it doesn’t effect execution beyond that.

Generally, the gradle.properties file is the best solution as it enforces the default encoding for the build JVM, and all JVMs that Gradle forks off (e.g. to execute tests) will inherit this default. Another option is to configure it for test execution only.

<code>
test {
  systemProperty “file.encoding”, “utf-8”
}
</code>

as I mentioned setting systemProp in gradle.properties did not work (possible BUG?)

but setting

test.systemProperty "file.encoding", "utf-8"

worked. Thanks!