Gradle's javac somehow ignores @SuppressWarnings annotations

I’m trying to get our warning count down. (To zero, if possible, but let’s start by trying to get it down to 4 digits.) One of the big offenders is ANTLR-generated Java code, because it seems to generate code optimised to maximise the number of warnings. (I even see redundant casts to Object.)

Thing is, though, it looks like their generated class does have a @SuppressWarnings("all") annotation on it, and when I run javac myself, does suppress all warnings.

When I run gradle’s compileJava, though, I still get all the warnings, despite the suppression.

The only settings I’m currently using are:

  tasks.withType(JavaCompile) {
    options.compilerArgs << "-Xlint:cast"
  }

Is there any reason why this would cause Gradle to run javac in some weird way which causes it to ignore the suppression? Because otherwise, I can’t figure out why the warnings only occur when Gradle is running javac, while running it myself does work as expected.

Any chance you could formalize the logic into a simplistic code example on GitHub that reproduces the issue? I could then go ahead and dig deeper.

This example is close to realistic. It uses ANTLR to generate the Java source which is full of warnings but does include a SuppressWarnings("all") which ostensibly is supposed to suppress them. The actual grammar is one straight out of some example page, though, rather than our real one.

I’ve also noticed that if I change the SuppressWarnings to specific warnings instead of “all”, that does suppress each individual type… so it’s literally only “all” which doesn’t work? I wonder if I’ve stumbled on some obscure javac thing where IntelliJ has been making it look like it works fine the whole time, when really it doesn’t work at all.