问题
I have a Maven project with two Maven modules A
and B
. A
contains the following Java module definition:
module A {
exports internal.util to B;
exports external.A;
}
B
contains the following Java module definition:
module B {
requires A;
exports external.B;
}
When I build the project, I get an error:
[WARNING] module-info.java:[16,106] module not found: B
Module B
exists but because Module A
is compiled before B
and does not depend on it, the compiler has no way of knowing that. Because I configured the compiler to treat warnings as errors (-Werror
), the build fails.
Seeing as I want to keep treating warnings as errors, what is the best way to resolve this problem?
- Is there a way to hint to the compiler that this module will be declared in the future?
- Is there a way to suppress all warnings of this type?
回答1:
I figured out a workaround by scanning through the JDK 11 source-code: -Xlint:-module
. I am still open to a better solution if someone finds one.
UPDATE: An alternative is to use --module-source-path
as demonstrated by https://stackoverflow.com/a/53717183/14731
Thank you Alan Bateman for pointing me in this direction!
回答2:
As I could infer from the question, your scenario is such that both the module A
and B
co-exists and the module A
does not depend on the module B
.
From a module system prospect, since A
makes a qualified export to the module B
, a warning is thrown if the module B
is not resolved on the modulepath while you build A
.
On IntelliJ-IDEA I could fix such an issue by adding a dependency of module B
to the module A
without any declaration changes. Though using the Maven framework, I couldn't imagine something without a cyclic dependency here, maybe the suggestion by khmarbaise could help.
Note: An alternate way to fix this though could also be to disable such warnings using the command-line arg :
-Xlint:-exports
Or as Alan points out for correction
-Xlint:-module
Thinking out loud, that would be since, the warning is a result of a qualified export, but about a module not found.
Useful: You could find the details over these command line args with javac command.
来源:https://stackoverflow.com/questions/53670052/how-to-define-qualified-exports-to-unknown-modules