title: How do I make IntelliJ IDEA honor user.language and user.country from Gradle config?
body: <p>I want to make sure my app always builds, runs tests, and runs using the correct locale, regardless of build &amp; run platform.</p>
  
  <p>So I have a simple unit test that checks that <code>new Locale("nb", "NO") == Locale.getDefault()</code></p>
  
  <p>Running the build with locale settings in either one of <code>_JAVA_OPTIONS</code>, <code>GRADLE_OPTS</code> or <code>JAVA_OPTS</code> works:</p>
  
  <pre><code>GRADLE_OPTS="-Duser.language=nb -Duser.country=NO" ./gradlew build
  </code></pre>
  
  <p>But I'm trying to avoid setting environment variables for every developer and build agent, so I tried setting these in <code>gradle.properties</code>:</p>
  
  <pre><code>org.gradle.jvmargs=-Duser.language=nb -Duser.country=NO
  </code></pre>
  
  <p>That doesn't work, since <code>Locale.getDefault()</code> now returns <code>en_US</code>.</p>
  
  <p>I tried setting them in <code>tasks.WithType(JavaCompile)</code>, that doesn't work either:</p>
  
  <pre><code>tasks.withType(JavaCompile) {
      options.forkOptions.jvmArgs += ['-Duser.language=nb', '-Duser.country=NO']
  }
  </code></pre>
  
  <p><code>tasks.withType(Test)</code> works however. Yay!</p>
  
  <pre><code>tasks.withType(Test) {
      jvmArgs += ['-Duser.language=nb', '-Duser.country=NO']
  }
  </code></pre>
  
  <p>But now to the problem: IntelliJ IDEA still doesn't see the <code>-Duser.*</code> VM options, and the unit test fails there.</p>
  
  <p>As a tip from @Andrej I tried setting the environment in <code>ProcessForkOptions</code> as described in <a href="https://youtrack.jetbrains.com/issue/IDEA-115426#comment=27-610182" rel="nofollow noreferrer">a JetBrains issue</a>:</p>
  
  <pre><code>tasks.withType(ProcessForkOptions) {
      environment("LC_ALL", "nb_NO.UTF-8")
  }
  </code></pre>
  
  <p>No success.</p>
  
  <p>How do I make it honor the Gradle config?  Do I have to manually set the VM options in the Run Configuration for the test?</p>