问题
My software builds use -Xlint -Werror
so I routinely run across compiler warnings that break my build. Every once in a while I run across a warning that I need to suppress, but it's always difficult to figure out which Xlint
option suppresses the warning I am seeing.
I'll give you a concrete example. I recently ran across:
[WARNING] module-info.java:[16,106] module not found:
org.bitbucket.cowwoc.requirements.guava
I searched the JDK 11 source-code and discovered this warning message declared at /src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties
as:
# 0: symbol
compiler.err.module.not.found=\
module not found: {0}
Now, it turns out that this is suppressed by -Xlint:-module
but that's not obvious from the documentation. -Xlint:-export
could made sense as well. I've also run across warnings in the past that couldn't be suppressed at all (these were subsequently fixed).
Instead of resorting to trial and error, is there a deterministic way to figure out which Xlint
option corresponds to each warning message? Is there some sort of mapping file somewhere in the JDK source codes?
UPDATE: I am using Maven 3.6.0, maven-compiler-plugin 3.8.0, JDK 11.0.1
回答1:
One way to do that, if somehow you're not able to access the online documentation could be using the command
javac --help-extra
This would list out the possible warnings that you could enable/disable. For example from javac 12-ea
:
回答2:
Alan Bateman pointed me in the right direction. It seems that the maven-compiler-plugin suppressing vital information. Here is the output from javac 11.0.1:
C:\Users\Gili\Documents\requirements\java\src\main\java\module-info.java:16: warning: [module] module not found: org.bitbucket.cowwoc.requirements.guava
exports org.bitbucket.cowwoc.requirements.java.internal.impl to org.bitbucket.cowwoc.requirements.guava;
Here is the corresponding output from maven-compiler-plugin:
[WARNING] /C:/Users/Gili/Documents/requirements/java/src/main/java/module-info.java:[16,106] module not found: org.bitbucket.cowwoc.requirements.guava
javac
mentions [module]
at the beginning of the warning, indicating that -Xlint:-module
will suppress this warning.
I filed a bug report here: https://issues.apache.org/jira/browse/MCOMPILER-367
来源:https://stackoverflow.com/questions/53676235/how-to-figure-out-which-xlint-option-corresponds-to-a-compiler-warning