Passing "-J-Duser.language" to gradle doesn't work

I want to have english messages when compiling.

After this post and this , I added the following to mybuild.gradle

compileJava {
  options.compilerArgs << '-J-Duser.language=en'
  options.fork = true
  options.forkOptions.executable = 'javac'
}

      

But I get ([] my translation, not the official one)

javac: 无效的标记[invalid flags]:  -J-Duser.language=en
用法[usage]: javac <options> <source files>
-help 用于列出可能的选项[for possible options]

      

In cmd

simple javac -J-Duser.language=en

really gives me english messages.

My question is:

  • What am I doing wrong?
  • How can I make gradle show the exact command javac

    used when compiling?
+3


source to share


1 answer


Instead of using, -J

you need to pass a flag options.forkOptions.jvmArgs

:



tasks.withType(JavaCompile) {
    options.fork = true
    options.forkOptions.jvmArgs += ["-Duser.language=en"]
}

      

+6


source







All Articles