How to pass -parameters javac flag to Java compiler via Gradle?

Czyzby picture Czyzby · May 26, 2016 · Viewed 13.1k times · Source

I have a Gradle-managed multi-project setup that relies on the new Java 8 -parameters compiler flag. I need 2 ways of including the compiler flag:

  • To test classes only (the main project should compile without parameter names attached).
  • To all compiled sources.

I've tried this:

  tasks.withType(JavaCompile) {
    options.compilerArgs << '-parameters'
    options.fork = true
    options.forkOptions.executable = 'javac'
  }

...but it does not seem to be working properly.

Answer

Crazyjavahacking picture Crazyjavahacking · May 27, 2016

You should use standard way of configuring Java compile plugin:

apply plugin: 'java'

compileJava {
    options.compilerArgs << '-parameters'
}