简体   繁体   中英

Gradle - change Java compiler output locale or encoding

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, eg 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.

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.

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

-Dfile.encoding={dest encoding}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM