Gradle erroneously quotes javac flag -processor

If I specify the following for a Java project in a build.gradle file:

compileJava.options.compilerArgs << "-processor org.openjdk.jmh.generators.BenchmarkProcessor"

and run a build, it fails with:

:compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> invalid flag: -processor org.openjdk.jmh.generators.BenchmarkProcessor

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

I’ve poked around and the root cause seems to be that the -processor flag and the value are quoted which seems to be troublesome for javac. I’ve created a minimal reproduction project at https://github.com/danielmitterdorfer/gradle-ap-repro which hopefully allows you reproduce this as easy as possible.

  • Gradle Version: 3.0
  • Operating System: Mac OS X 10.11.6 x86_64
  • Is this a regression? If yes, which version of Gradle do you know it last worked for? This is not a regression, originally found in Gradle 2.13, does not work with Gradle 3.0 either

Hi Daniel,

you need to add each String as a different compiler argument as follows:

compileJava.options.compilerArgs.addAll(["-processor",  "org.openjdk.jmh.generators.BenchmarkProcessor"])

There is also an example in the DSL documentation of CompileOptions.

Regards,
Stefan

Hi Stefan,

thanks for the hint. It worked perfectly. Don’t know how I could miss this…

Daniel