无法使用--module-source-path解析模块 [英] Unable to resolve module using --module-source-path
问题描述
紧跟如何定义向未知模块的合格导出?我发布了
Following up on How to define qualified exports to unknown modules? I've posted a testcase with two modules: core
and plugin
.
core
尝试使用合格的导出将包暴露给plugin
,但是编译器抱怨plugin
不存在.遵循Alan Bateman的建议,我尝试将指向core
的--module-source-path <path-of-plugin> --module plugin
指向plugin
,但是编译器抱怨:
core
tries to expose a package to plugin
using qualified exports but the compiler complains that plugin
does not exist. Following up on Alan Bateman's recommendation, I tried adding --module-source-path <path-of-plugin> --module plugin
pointing from core
to plugin
but the compiler complains:
module plugin not found in source path
为什么编译器无法找到模块plugin
?
Why isn't the compiler able to find module plugin
?
推荐答案
我通过反复试验弄清楚了.
I figured it out through trial and error.
- 使用
--module-source-path ${project.basedir}/../*/src/main/java
确保编译器可以看到两个模块的源代码. - 使用
--module core
可以确保尽管看到了所有模块,编译器仍只构建core
. - 告诉
maven-jar-plugin
从classes/${module.name}
而不是仅从classes
打包类,因为module-source-path
导致输出以模块名称作为前缀.我没有找到禁用此前缀的方法.
- Use
--module-source-path ${project.basedir}/../*/src/main/java
to make sure the compiler can see the source-code of both modules. - Use
--module core
to make sure that the compiler only buildscore
in spite of seeing all modules. - Tell
maven-jar-plugin
to package classes fromclasses/${module.name}
instead of justclasses
becausemodule-source-path
causes the output to be prefixed by the module name. I have not found a way to disable this prefix.
固定代码可以在> https://bitbucket.org/cowwoc/qualified中找到-exports-testcase/
注意事项:仅当模块目录名称(由*
解析的组件)与Java模块名称匹配时,此技术才有效.在此特定示例中,模块core
的源位于目录core/src/main/java
中.另一方面,如果目录名称为core
,但相应的Java模块为org.bitbucket.core
,则编译将失败,并显示module org.bitbucket.core not found in module source path
.
Caveat: This technique only works if the module directory name (the component resolved by *
) matches the Java module name. In this particular example the module core
had its sources in directory core/src/main/java
. If, on the other hand, the directory name was core
but the corresponding Java module was org.bitbucket.core
then the compilation would fail with module org.bitbucket.core not found in module source path
.
这篇关于无法使用--module-source-path解析模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!