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