25

We use Gradle 2.1 and java plugin. During compileJava different warnings occur, for example:

warning: [options] bootstrap class path not set in conjunction with -source 1.7
Note: ../SomeClass.java uses or overrides a deprecated API.

We know what they mean but won't fix them (don't ask, other thread :) Is there a way to avoid these messages somehow? They disturb the output a lot:

:project1:compileJava
warning: [options] bootstrap class path not set in conjunction with -source 1.7
Note: SomeClass.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 warning
:project1:processResources
:project1:classes
:project1:jar
:project2:compileJava
warning: [options] bootstrap class path not set in conjunction with -source 1.7
1 warning
:project2:processResources
:project2:classes
:project2:jar
:project2:war

Isn't is possible for example to redirect the stderr stream during compileJava so that we can grep out the warnings? Or is there another way?

Marcel
  • 4,054
  • 5
  • 36
  • 50
  • I used 'compileJava.options.warnings = false' and 'compileTestJava.options.warnings = false' but this just solved some problems. To avoid to much waste of time I went to the other teams and solved the 'problem' on their code side. – Marcel Apr 13 '15 at 12:29
  • Ugh, I hate the fact that Gradle makes you edit the build files. This has to be the biggest reason I would stick to Maven if it was my choice. – Sridhar Sarnobat Oct 28 '19 at 18:15

4 Answers4

11

try this:

tasks.withType(JavaCompile) {
    options.warnings = false
}
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
Rene Groeschke
  • 27,999
  • 10
  • 69
  • 78
  • 1
    this removes for me that warnings about bootstrap, but not the notes about deprecation. I'm not sure if it was clear that I also want to avoid them, nevertheless +1 – Marcel Feb 18 '15 at 08:02
  • Doesen't get rid of `sun.*` deprecation warnings for men. – Sridhar Sarnobat Oct 05 '20 at 23:29
2

Try adding:

options.compilerArgs += '-Xlint:-deprecation'
cmcginty
  • 113,384
  • 42
  • 163
  • 163
  • Could not get unknown property 'options' – xeruf Nov 12 '17 at 23:46
  • 4
    @Xerus i think cmginty means to put that line in a JavaCompile task configuration block, ie. `tasks.withType(JavaCompile) { options.compilerArgs += '-Xlint:-deprecation' }` – jerryb Nov 19 '17 at 22:04
2

No answer posted so far that currently works (Gradle 4.0.1), so here's what does work:

options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219
  • 1
    I hate how gradle doesn't allow such options at invocation time. This is why I prefer maven. – Sridhar Sarnobat Jun 12 '20 at 02:40
  • 1
    @SridharSarnobat You could easily define a specific property, and set that on the command line to do suppress exactly that what you want to be suppressed. – GhostCat Feb 15 '21 at 11:55
0

I think it really depends on the warnings. For the warnings I was getting, this worked:

    tasks.withType(JavaCompile) {
        options.compilerArgs += ["-nowarn", "-XDenableSunApiLintControl"]
    }

Sanity restored.

Sridhar Sarnobat
  • 25,183
  • 12
  • 93
  • 106