After upgrading a Maven project to Java 9 and adding a module descriptor, javac
complains about a transitive dependency for an automatic module:
[WARNING] /.../src/main/java/module-info.java:[3,35]
requires transitive
directive for an automatic module
An example module-info.java
to reproduce the problem:
module com.example.mymodule {
exports com.example.mymodule.myexportedpackage;
requires transitive com.google.common;
}
The meaning of this warning is completely clear, here are some related links:
- What's the difference between requires and requires transitive statements in Java 9?
- Why does javac complain about named automatic-modules?
- Related OpenJDK issue
The question is — how to suppress this warning, without fixing the actual issue, and without disabling all the other javac
warnings?
I've tried the following options, but none of them worked:
@SuppressWarnings("module")
inmodule-info.java
@SuppressWarnings("all")
inmodule-info.java
-Xlint:all,-module
command line option
Unfortunately, I cannot fix the actual issue (for now) because "my" module has return types and annotations from third-party (automatic) modules (e.g. Guava). Thus, if I'd use "requires com.google.common" (without transitive
), then there would be a different warning, e.g.:
[WARNING] .../MyClass.java:[25,20] class
com.google.common.collect.Table
in modulecom.google.common
is not indirectly exported usingrequires transitive
And of course I cannot define module descriptors for the third-party libraries (which are automatic modules right now).
I'm using -Werror
which I'd prefer to keep, so the warning isn't merely annoying...
P.S. I do not intend to publish my artifacts to any public repositories.
-Xlint:-requires-transitive-automatic
and it worked. Thank you so much. – Shiksa