3

Can one configure Gradle to change java compiler output locale or encoding?

The problem: gradle in run on Windows with non English default Local (in particular it is Chinese)

There is possibility to do that configuring Java, e.g. Setting java locale settings .

Can Gradle do (that is just for this build, CI job) ?

UPDATE:

As Vadim referenced, for source encoding, this snippet is used.

tasks.withType(Compile) {
    options.encoding = 'UTF-8'
}

Details: Gradle calls Java compile, that defaults to system Locale (in my case it is Chinese). So when error appears, it is shown in Chinese. Java documentation says to configure via environment variable. But I want to do it only for this build.gradle ... Possibly I need to change that environment variable before and after compilation automatically, it Gradle does not provide such costomization.

Community
  • 1
  • 1
Paul Verest
  • 60,022
  • 51
  • 208
  • 332
  • You might want to do another update, in latest gradle (I'm not sure which version it started with), task has been renamed from Java to JavaCompile and you need to use tasks.withType(JavaCompile) – Vadym Chekan Dec 18 '15 at 17:46
  • It has changed in Gradle 2.0, and that is point of this question: How to do it without changing `build.gradle`? – Paul Verest Dec 28 '15 at 14:30

2 Answers2

2

The question sounds strange to me. Java compiler has an input: source files and an output: class files. I believe you are talking about specifying encoding for an input. Of course it is possible to customize it with Gradle. See for example http://mrhaki.blogspot.cz/2012/06/gradle-goodness-set-java-compiler.html (note that Compile task is changed to JavaCompile in Gradle 2.0).

The output is a class file and it does not depend on your language.

Radim
  • 4,721
  • 1
  • 22
  • 25
0

there is no flag/option to set in gradle.
but if you run javadoc in cmd, you can set

-Dfile.encoding={dest encoding}
Martin Brisiak
  • 3,872
  • 12
  • 37
  • 51