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:
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")
in module-info.java
@SuppressWarnings("all")
in module-info.java
-Xlint:all,-module
command line optionUnfortunately, 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.
You can also just use @SuppressWarnings
like so:
@SuppressWarnings({ "requires-automatic", "requires-transitive-automatic" })
module foo {
// ...
}
The JDK itself uses this technique.
You could try out the option of switching off the warning using
-Xlint:-requires-transitive-automatic
The changes for which were merged with JDK-8178011 stating:-
There should be two new warnings:
- when a named module "requires transitive" an automatic module (default on)
- when a named module "requires" an automatic module (default off)
Inferring this from the changes made here and also from the edit to the JEP 261: Module System which confirms that(emphasis mine):-
In both of the modular modes the compiler will, by default, generate various warnings related to the module system; these may be disabled via the option
-Xlint:-module
.More precise control of these warnings is available via the exports, opens, requires-automatic, and requires-transitive-automatic keys for the
-Xlint
option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With