使用 Java 9 个模块,多个模块是否能够导出同一个包?
With Java 9 Modules, will multiple modules be able to export the same package?
我正在尝试使用适合 Java 9 模块系统的最佳实践,这样我就可以做更少的工作来获得好处(我们的系统现在真的可以从一些模块化中受益)。
当前标准是否允许模块 A 导出包 com.example.foo 以及模块 B 导出包 com.example.foo?
作为一个相关的问题,如果相关的话,是这一点是否真的已经解决或者它是否仍然不是最终的。
根据最新的State of the Module System,模块系统确保"every module reads at most one module defining a given package, and that modules defining identically-named packages do not interfere with each other."和:"When code in a module refers to a type in a package then that package is guaranteed to be defined either in that module or in precisely one of the modules read by that module."
这意味着两个不同的模块可以导出相同的包,如果 - 在构建时和 运行 时 - 没有模块同时依赖于 A 和 B,并且如果 A 和 B 不依赖互相依赖。理论上,您可以有两个导出相同包的模块,并一次将它们与另一个依赖模块一起使用。
我还建议,正如已经建议的那样,最好的做法是让一个包由一个模块而不是两个模块导出。
我正在尝试使用适合 Java 9 模块系统的最佳实践,这样我就可以做更少的工作来获得好处(我们的系统现在真的可以从一些模块化中受益)。
当前标准是否允许模块 A 导出包 com.example.foo 以及模块 B 导出包 com.example.foo?
作为一个相关的问题,如果相关的话,是这一点是否真的已经解决或者它是否仍然不是最终的。
根据最新的State of the Module System,模块系统确保"every module reads at most one module defining a given package, and that modules defining identically-named packages do not interfere with each other."和:"When code in a module refers to a type in a package then that package is guaranteed to be defined either in that module or in precisely one of the modules read by that module."
这意味着两个不同的模块可以导出相同的包,如果 - 在构建时和 运行 时 - 没有模块同时依赖于 A 和 B,并且如果 A 和 B 不依赖互相依赖。理论上,您可以有两个导出相同包的模块,并一次将它们与另一个依赖模块一起使用。
我还建议,正如已经建议的那样,最好的做法是让一个包由一个模块而不是两个模块导出。