Monday, June 13, 2016

How to pass parameters for Java compiler like `-Xlint:unchecked` in Gradle

If you encounter the following warning in Gradle:

Note: /Users/izeye/IdeaProjects/trust/src/test/java/com/ctb/trust/SpringBootActuatorTests.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

you can add the following configuration:

tasks.withType(JavaCompile) {
    options.compilerArgs << '-Xlint:unchecked'
}

And then you will see the following detail:

Map<String, Object> health = response.getBody();
                                                             ^
  required: Map<String,Object>
  found:    Map
1 warning

Reference:
https://discuss.gradle.org/t/it-seems-that-javac-compiler-options-is-not-passed-to-compilejava-task-on-gradle2-6-with-jdk8u60/11271

No comments:

Post a Comment