2

good day, stackoverflow.

I've met with the fact, that setting with encoding options for my project for gradle in build.gradle, gradle.properties, gradlew, gradlew.bat does nothing in Intellij Idea. When I run task from command line such

gradlew name_of_the_task

it runs ok and the encoding settings that I've set in gradlew.bat are implemented. But when I run build for the same task in Intellij Idea it seems that this setting is not set.

I've tried many variants to set the jvm property, and the only 3 ways helps me:

  1. the idea64.vmoptions file where i specified the -Dfile.encoding=utf8 or
  2. The help - edit custom vm options... with the same specification or
  3. File - settings - global gradle settings - gradle vm options.

In any of this cases project runs as it meant to run. Without that there is decoding problem. How can I set this param directly in project?

ValerianTi
  • 81
  • 2
  • 11
  • What problem exactly do you see when executing gradle task from IDE? Have you tried setting project encoding in File | Settings | Editor | **File Encodings**? – Andrey Sep 07 '18 at 08:46
  • well, I got an encoding problem when I try to output in console chinese characters. Yes, I've tried that options with no luck – ValerianTi Sep 07 '18 at 09:19

1 Answers1

0

This one helps. Setting the default Java character encoding?

    System.setProperty("file.encoding", "UTF-8");
    Field cs = Charset.class.getDeclaredField("defaultCharset");
    cs.setAccessible(true);
    cs.set(null, null);

This code allows to set encoding on runtime.

ValerianTi
  • 81
  • 2
  • 11