File encoding ignored by compiler
Answered
Hello,
I'm currently working in a Gradle project on Windows 10 with IntelliJ 2019.3. I use AdoptOpenJDK 11 as JDK.
Whenever I try to compile my files they are interpreted by the compiler as Windows 1252 encoded even though they are encoded in UTF-8.
Encoding is set in Settings -> Editor -> File Encodings to UTF-8 for Gobal and Project Encoding.
I only have the problem with this specific Project. Other Projects with the same configuration work fine (only difference: no gradle).
I tried:
- Invalidate and Restart
- Re-encoding file
- Recreating .idea and .gradle folder
Does anyone know how to fix this?
Thank you in advance
Best regards,
Simon
Please sign in to leave a comment.
Please note that Settings (Preferences) | Editor | File Encodings are effective when you create new new files only.
AFAIU you tried to change the encoding for the file manually in IDE status bar? After what actions do you see the encoding changed back and how do you know the encoding is changed back? Also file types are these?
Also make sure the encoding for this file is not specified explicitly.
I used this to find out how the files are actually encoded.
I did only change the encoding manually via the statusbar to test if it's a encoding problem, but I did not change it for the files generally. The files stayed UTF-8 encoded as in the beginning.
The file type is .java and the encoding is not specified explicitly.
So the source files are encoded in UTF-8 but after compilation you see compiled files are Windows 1252 encoded?
Do you build project by Gradle or IDE (have Gradle or IntelliJ IDEA runner set for Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Gradle | 'Build and run using')?
What result you see when build by Gradle from command line?
Do you see issue only with this project? Can you provide a sample project and your File | Export Settings... jar to check? Please also provide idea.log file.
For uploading you can use ftp://ftp.intellij.net/.uploads / https://uploads.services.jetbrains.com or any file sharing service.
I have exactly the same problem since I upgraded from 2019.1.2 to 2019.3.2.
Do you use Gradle for Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Gradle | Build and run using?
Does it help to add this to your build.gradle file:
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
If not could you please provide information requested in my previous comment? Thank you.
No.
My Gradle settings:
Build and run using: IntelliJ IDEA
My build.gradle already contains
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'I've uploaded a sample project (gdp.zip). The compiled class file (Ueb01a.class) is ANSI encoded (checked with Notepad++).
Thanks for the sample project.
>The compiled class file (Ueb01a.class) is ANSI encoded (checked with Notepad++).
I've compiled it by the Gradle from the command line: I see the same result. Doesn't look like an IDE issue.