简体   繁体   中英

How to set global gradle settings (gradle vm options) in intellij idea programmatically?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM