I want to make sure my app always builds, runs tests, and runs using the correct locale, regardless of build & run platform.
So I have a simple unit test that checks that new Locale("nb", "NO") == Locale.getDefault()
Running the build with locale settings in either one of _JAVA_OPTIONS
, GRADLE_OPTS
or JAVA_OPTS
works:
GRADLE_OPTS="-Duser.language=nb -Duser.country=NO" ./gradlew build
But I'm trying to avoid setting environment variables for every developer and build agent, so I tried setting these in gradle.properties
:
org.gradle.jvmargs=-Duser.language=nb -Duser.country=NO
That doesn't work, since Locale.getDefault()
now returns en_US
.
I tried setting them in tasks.WithType(JavaCompile)
, that doesn't work either:
tasks.withType(JavaCompile) {
options.forkOptions.jvmArgs += ['-Duser.language=nb', '-Duser.country=NO']
}
tasks.withType(Test)
works however. Yay!
tasks.withType(Test) {
jvmArgs += ['-Duser.language=nb', '-Duser.country=NO']
}
But now to the problem: IntelliJ IDEA still doesn't see the -Duser.*
VM options, and the unit test fails there.
As a tip from @Andrej I tried setting the environment in ProcessForkOptions
as described in a JetBrains issue:
tasks.withType(ProcessForkOptions) {
environment("LC_ALL", "nb_NO.UTF-8")
}
No success.
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?