1

I need to build a Maven project on a macOS 10.14 machine with Java 8.

For various reasons, I would prefer to keep my system using my "real" locale (that is, my system settings panel should list "German" as the locale, time, currency and number formats), but I need my code to be compiled using the "C" locale.

I tried setting the locale using classical Unix means, like LANG and LC_* environment variables, and also using the user.language (etc.) maven options. In both cases, I was unsuccessful: my floating point numbers were output using the German "," as decimal separator, and mvn --status listed "de_DE" as the default locale.

It seems that macOS handles locale settings for Java a bit different than Linuxes. So, how can I get a maven job to use a different locale than the rest of the system, without

  1. changing my codebase (that includes the pom.xml)
  2. Altering macOS's system settings?
jstarek
  • 1,522
  • 1
  • 12
  • 23
  • If you don't set the locale in the POM, won't the project build incorrectly for other developers that don't use the "C" locale in their local development environments? – user944849 Feb 04 '19 at 21:44
  • @user944849: Everyone else on the project uses US locales, so the other people around are not affected. But viewed more generally, yes, you are right. – jstarek Feb 05 '19 at 11:04

1 Answers1

0

FYI: https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html

To set locale for compilation you can configure it with maven-compiler-plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <fork>true</fork>
        <compilerArgs>
            <arg>-J-Duser.language=de_DE</arg>
        </compilerArgs>
    </configuration>
</plugin>

To set locale for maven itself, the best way is to use .mvn folder with jvm.config file:

.mvn
    jvm.config
src
    main
        ...
    test
        ...
pom.xml

jvm.config:

-Duser.language=en -Duser.country=GB

FYI (about .mvn folder): https://maven.apache.org/docs/3.3.1/release-notes.html

Gmugra
  • 468
  • 7
  • 10