5

I want to have English messages when compiling.

Following this post and this, I added the following to my build.gradle

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

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

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

In cmd, a simple javac -J-Duser.language=en do gives me English messages.

My question:

  1. What am I doing wrong?
  2. How can I make gradle show the exact javac command used when compiling?
Community
  • 1
  • 1
zjk
  • 2,043
  • 3
  • 28
  • 45

1 Answers1

8

Instead of using -J, passing the flag to options.forkOptions.jvmArgs should work:

tasks.withType(JavaCompile) {
    options.fork = true
    options.forkOptions.jvmArgs += ["-Duser.language=en"]
}
Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259