简体   繁体   English

Gradle - 更改 Java 编译器输出区域设置或编码

[英]Gradle - change Java compiler output locale or encoding

Can one configure Gradle to change java compiler output locale or encoding?可以配置 Gradle 来更改 Java 编译器输出区域设置或编码吗?

The problem: gradle in run on Windows with non English default Local (in particular it is Chinese)问题:在 Windows 上运行的 gradle 使用非英语默认本地(特别是中文)

There is possibility to do that configuring Java, eg Setting java locale settings .有可能配置 Java,例如设置 Java 语言环境设置

Can Gradle do (that is just for this build, CI job) ? Gradle 可以做(仅针对此构建、CI 工作)吗?

UPDATE:更新:

As Vadim referenced, for source encoding, this snippet is used.正如 Vadim 所引用的,对于源编码,使用此代码段。

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

Details: Gradle calls Java compile, that defaults to system Locale (in my case it is Chinese).详细信息:Gradle 调用 Java 编译,默认为系统 Locale(在我的情况下是中文)。 So when error appears, it is shown in Chinese.所以当出现错误时,它是用中文显示的。 Java documentation says to configure via environment variable. Java 文档说要通过环境变量进行配置。 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.但我只想为这个build.gradle做这build.gradle ......可能我需要在编译前后自动更改该环境变量,Gradle 不提供这种定制化。

The question sounds strange to me.这个问题对我来说听起来很奇怪。 Java compiler has an input: source files and an output: class files. Java 编译器有一个输入:源文件和一个输出:类文件。 I believe you are talking about specifying encoding for an input.我相信您正在谈论为输入指定编码。 Of course it is possible to customize it with Gradle.当然,可以使用 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).参见例如http://mrhaki.blogspot.cz/2012/06/gradle-goodness-set-java-compiler.html (注意Compile任务在 Gradle 2.0 中更改为JavaCompile )。

The output is a class file and it does not depend on your language.输出是一个类文件,它不依赖于您的语言。

there is no flag/option to set in gradle.在 gradle 中没有要设置的标志/选项。
but if you run javadoc in cmd, you can set但是如果你在cmd中运行javadoc,你可以设置

-Dfile.encoding={dest encoding}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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