LoginSignup
17
14

More than 3 years have passed since last update.

gradleプロジェクトの時IntelliJのコンソールが文字化けする

Last updated at Posted at 2019-06-27

自宅WindowsのIntelliJで発生。
会社でも同じようにIntelliJを使っているのだがそちらはちゃんと変換される。

Hoge.java
public class Hoge {
    public static void main(String[] args) {
        System.out.println("あああ");
    }
}
実行結果
あああ

プロセスは終了コード 0 で完了しました

ちゃんと動く方の情報

変換できている方の設定関連を調べてみた。

バージョン情報

image.png

IntelliJ設定

image.png

カスタムVM

.IdeaIC2019.1/config/idea64.exe.vmoptions
# Custom VM options (Generated by Pleiades Installer)
# See https://pleiades.io/pages/pleiades_jetbrains_manual.html
#-Xms128m
#-Xmx750m
-XX:ReservedCodeCacheSize=240m
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50
-ea
-Dsun.io.useCanonCaches=false
-Djava.net.preferIPv4Stack=true
-Djdk.http.auth.tunneling.disabledSchemes=""
-XX:+HeapDumpOnOutOfMemoryError
-XX:-OmitStackTraceInFastThrow
-Xverify:none
-javaagent:C:\Users\*******\.IdeaIC2019.1\config\jp.sourceforge.mergedoc.pleiades\pleiades.jar
-Dconsole.encoding=UTF-8
-Dfile.encoding=UTF-8

設定ファイルらしきモノ

JetBrains\IntelliJ IDEA Community Edition 2019.1.2\bin\idea64.exe.vmoptions

bin\idea64.exe.vmoptions
-Xms128m
-Xmx750m
-XX:ReservedCodeCacheSize=240m
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50
-ea
-Dsun.io.useCanonCaches=false
-Djava.net.preferIPv4Stack=true
-Djdk.http.auth.tunneling.disabledSchemes=""
-XX:+HeapDumpOnOutOfMemoryError
-XX:-OmitStackTraceInFastThrow

調べる

ユーザフォルダに何やら怪しそうなやつがいる。
C:\Users\*****\.IdeaIC2019.1\config

キャッシュの削除も検討する。
Qiita - IntelliJ Ideaのキャッシュを消す方法

試した結果

ここまでやってもだめ。
なんで???同じじゃん。

ビルド方法が違った

ふとコンソールに目をやると

> Task :compileJava
> Task :processResources NO-SOURCE
> Task :classes
…

こんなのが出力されていた。
(これgradleプロジェクトで作ったなあ…。会社のは普通のプロジェクトだったなあ…。)

ググってみたら以下のサイトにあたった。
Gradleで文字エンコーディングを指定する方法

build.gradleに以下を追記。

build.gradle
plugins {
    id 'java'
}

group 'com_tutorial'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    // https://mvnrepository.com/artifact/org.projectlombok/lombok
    compile group: 'org.projectlombok', name: 'lombok', version: '1.18.8'

    testCompile group: 'junit', name: 'junit', version: '4.12'
}

// 以下の行を記載
tasks.withType(AbstractCompile)*.options*.encoding = tasks.withType(GroovyCompile)*.groovyOptions*.encoding = 'UTF-8'

ビンゴ。変換された!

実行結果
あああ

プロセスは終了コード 0 で完了しました

参考になりそうなリンク集

結局全部違ったけど。

IntelliJ IDEA でコンソールのTomcatログが文字化けしたときに設定した3点
https://qiita.com/qurage/items/cb57bb9c942e55ed06d1

intellij-ideaのコンソールでの文字化けの原因について
https://ja.stackoverflow.com/questions/42721/intellij-idea%E3%81%AE%E3%82%B3%E3%83%B3%E3%82%BD%E3%83%BC%E3%83%AB%E3%81%A7%E3%81%AE%E6%96%87%E5%AD%97%E5%8C%96%E3%81%91%E3%81%AE%E5%8E%9F%E5%9B%A0%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6

公式ヘルプ
https://pleiades.io/help/idea/configuring-individual-file-encoding.html

17
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
14