[英]JDK9 Automatic Modules and "Split Packages" Dependencies
I am converting a java project to use modules.我正在转换一个 java 项目以使用模块。 One of my modules depends on
hamcrest
library, and it needs both of the jar files hamcrest.core
and hamcrest.library
.我的一个模块依赖于
hamcrest
库,它需要两个 jar 文件hamcrest.core
和hamcrest.library
。 These two jar files both have org.hamcrest
package.这两个 jar 文件都有
org.hamcrest
包。 So when my module wants to treat these two jars as automatic modules, it fails because two modules in a module-path cannot have packages with same name.因此,当我的模块想要将这两个 jar 视为自动模块时,它会失败,因为模块路径中的两个模块不能有同名的包。 I searched a lot and found some related stuff on stackoverflow.
我搜索了很多,在stackoverflow上找到了一些相关的东西。 It seems that I have two reasonable options if I do not want to rebuild those dependencies:
如果我不想重建这些依赖项,我似乎有两个合理的选择:
So here are my questions:所以这里是我的问题:
Thanks in advance提前致谢
Ok I finally managed to solve it like this:好的,我终于设法解决了这个问题:
hamcrest-all
and add dependencies on hamcrest-core
and hamcrest-library
.hamcrest-all
的新 maven 模块,并添加对hamcrest-core
和hamcrest-library
依赖。maven-assembly-plugin
to this module with appendAssemblyId
set to false.maven-assembly-plugin
添加到此模块, appendAssemblyId
设置为 false。hamcrest-core
and hamcrest-library
from other maven modules and instead add dependency to hamcrest-all
.hamcrest-core
和hamcrest-library
依赖,而是添加对hamcrest-all
依赖。hamcrest-core
and hamcrest-library
when including dependency to hamcrest-all
.hamcrest-all
依赖时,排除hamcrest-core
和hamcrest-library
。 What it actually does is that it unpacks hamcrest-core
and hamcrest-library
in the jar file created for hamrest-all
.它的实际作用是将
hamcrest-core
和hamcrest-library
解压到为hamrest-all
创建的 jar 文件中。 And because each jar file is treated as one module by JMPS, the problem is gone :)并且因为每个 jar 文件都被 JMPS 视为一个模块,所以问题消失了:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.