Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing “-J-Duser.language” to gradle not working

Tags:

gradle

javac

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?
like image 708
zjk Avatar asked Sep 13 '14 11:09

zjk


1 Answers

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"]
}
like image 167
Peter Niederwieser Avatar answered Nov 15 '22 05:11

Peter Niederwieser