如何抑制“需要自动模块的传递指令”警告得当吗? [英] How to suppress the "requires transitive directive for an automatic module" warning properly?
问题描述
将Maven项目升级到Java 9并添加模块描述符后, javac
抱怨自动模块的传递依赖:
[警告] /.../src/main/java/module-info.java:[3,35]
要求自动模块的传递
指令
示例 module-info.java
重现问题:
module com.example.mymodule {
export com.example.mymodule.myexportedpackage;
需要传递com.google.common;
}
此警告的含义完全清楚,这里有一些相关的链接:
问题是 - 如何取消此警告而不修复实际问题,并且不会禁用所有其他 javac
警告?
我尝试了以下选项,但没有一个可以使用:
-
@
module-info.java中的SuppressWarnings(module)
-
@
module-info.java
-
中的SuppressWarnings(all)
- Xlint:all,-module 命令行选项
不幸的是,我无法修复实际问题(暂时),因为my模块具有来自第三方(自动)模块的返回类型和注释(例如番石榴)。因此,如果我使用require com.google.common(没有 transitive
),则会有不同的警告,例如:
[警告] ... / MyClass.java:[25,20] class
com.google.common.collect.Table $模块
com.google.common
中的c $ c>未使用间接导出,需要传递
当然,我无法为第三方库(现在是自动模块)定义模块描述符。
我正在使用 -Werror
我宁愿保留,所以警告不仅仅是烦人的...
PS我不打算将我的工件发布到任何公共存储库。
您可以尝试使用
<关闭警告的选项pre>
-Xlint:-requires-transitive-automatic
与 JDK-8178011 合并的更改说明: -
应该有两个新的警告:
$ b时,需要传递自动模块(默认开启)
- 当一个命名的模块当需要模块需要自动模块(默认关闭)
$ b
推断这个从此处所做的更改以及从编辑到 JEP 261:模块系统确认(强调我的): -
在两种模块化模式下,编译器默认会生成
与模块系统相关的各种警告;这些可以通过选项-Xlint:-module
禁用
。
更精确地控制这些警告
可以通过导出,打开,需要自动和
需要 - 传递 - 自动-Xlint
选项的键。
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.
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.
这篇关于如何抑制“需要自动模块的传递指令”警告得当吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!