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

后端 未结 4 2156
小鲜肉
小鲜肉 2021-02-07 00:48

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
相关标签:
4条回答
  • 2021-02-07 00:54

    Answer from @Crazyjavahacking is correct

    Also, check that you doesn't redifine it, like me, in a subproject that uses others args (mapstruct in my case) :

    options.compilerArgs = ['-Amapstruct.defaultComponentModel=spring'] // do not do this

    Always append the args options.compilerArgs << '-Amapstruct.defaultComponentModel=spring'

    Hope it can save some time to someone else, i personnaly lost 2 hours since i totally forgot this line in the subproject and was concentrating on the main build.gradle

    0 讨论(0)
  • 2021-02-07 00:54
    compileJava {
      options.compilerArgs.addAll(['--release', javaVersion])
    }
    
    0 讨论(0)
  • 2021-02-07 01:04

    You should use standard way of configuring Java compile plugin:

    apply plugin: 'java'
    
    compileJava {
        options.compilerArgs << '-parameters'
    }
    
    0 讨论(0)
  • 2021-02-07 01:16

    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"]
    }
    
    0 讨论(0)
提交回复
热议问题