Add UTF-8 support for Gradle

Source: Internet
Author: User

Gradle uses system character encoding by default, most Chinese systems use GBK encoding

But most programmers use UTF-8 to write all kinds of Java files and other resource files

It is easy to make errors at compile time, such as the following error:

"Warning: Encoding GBK non-mapped characters"

There are two ways to add UTF-8 support to Gradle

First, in our project configuration file Build.gradle, add the following statement last

Tasks.withtype (javacompile) {      "UTF-8"  }

Thus, when the project is Gradle packaged, the Java file is compiled with UTF-8 encoding.

The other is to modify the gradle that we downloaded, so that the default encoding is UTF-8, and it doesn't need to be configured for each project

Open the Gradle.bat file under the Gradle/bin directory, modify the code near line 12 to

Set default_jvm_opts= "Dfile.encoding=utf-8"

Also use software like notepad++ to open Gradle file

Edit the code around line 10th to

Set default_jvm_opts= "Dfile.encoding=utf-8"

This modifies the Gradle default character encoding to UTF-8.

Bloggers think that the first method is more general, after all, our project release will let different programmers compile and debug

So the first method is more versatile.

Add UTF-8 support for Gradle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.