1. 程式人生 > >Gradle打包時出現警告:編碼 GBK 的不可對映字元的問題

Gradle打包時出現警告:編碼 GBK 的不可對映字元的問題

  對於gradle2.0以前的版本,在build.gradle的最後加上

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

對於gradle2.0以後的版本,在build.gradle的最後加上

tasks.withType(JavaCompile) { options.encoding = "UTF-8" }

Compile已經被重新命名為JavaCompile

要設定 Groovy sources, 使用tasks.withType(GroovyCompile) { groovyOptions.encoding = "UTF-8" }

.

設定Scala sources, 使用tasks.withType(ScalaCompile) { scalaCompileOptions.encoding = "UTF-8" }.