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

18,871

Solution 1

You should use standard way of configuring Java compile plugin:

apply plugin: 'java'

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

Solution 2

For Android projects, one can add e.g. the below in the gradle android scope.

// Used to get more info from dagger regarding binding compile errors
// see https://github.com/google/dagger/wiki/Dagger-2.17-@Binds-bugs
tasks.withType(JavaCompile) {
    options.compilerArgs += ["-Adagger.floatingBindsMethods=enabled"]
}
Share:
18,871
Czyzby
Author by

Czyzby

Backend developer turned data scientist.

Updated on June 07, 2022

Comments

  • Czyzby
    Czyzby about 2 years

    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.