了解JPMS模块的错误

时间:2020-09-25 23:57:47

标签: java spring spring-data java-platform-module-system spring-data-jdbc

我很难理解这些错误的含义,更不用说开始解决它们了。我正在尝试将Java平台模块(使用jdk 14)与一个简单的“基于渐变的多模块”项目一起使用(一切都与jdk 8完美配合)。该项目使用spring-boot和spring-data-jdbc。其实我的核心依赖项是

implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-freemarker'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.projectlombok:lombok'

虽然我在每个项目源根目录中都添加了module-info.java,但是我的IDE(intellJ)非常友好,可以提示我要导出/需要哪些模块,并且在尝试编译之前,所有模块看起来都很不错。

我在此处包括指向此问题的主题项目的git repo链接-https://github.com/m41na/todo-modules-demo

如果您遇到这些(或类似的)问题,能否请您阐明如何解决这些问题?

error: the unnamed module reads package org.springframework.data.jdbc.core.convert from both spring.data.jdbc and spring.data.relational
error: module spring.context reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc
error: module spring.boot.starter.data.jdbc reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc
error: module spring.boot.starter.jdbc reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc
error: module spring.data.jdbc reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc
error: module spring.boot.starter reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc
error: module spring.jdbc reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc
error: module spring.tx reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc
error: module spring.boot.autoconfigure reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc
error: module spring.boot reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc
error: module spring.aop reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc
error: module spring.expression reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc
the unnamed module reads package org.springframework.data.jdbc.core.convert from both spring.data.jdbc and spring.data.relational

error: module spring.core reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc
error: module spring.boot.starter.logging reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc
error: module logback.classic reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc
error: module org.apache.logging.slf4j reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc
module spring.context reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc

error: module jul.to.slf4j reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc
error: module org.slf4j reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc
module spring.boot.starter.data.jdbc reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc

error: module java.annotation reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc
module spring.boot.starter.jdbc reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc

error: module org.yaml.snakeyaml reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc
error: module spring.jcl reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc
module spring.data.jdbc reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc

error: module logback.core reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc
error: module spring.beans reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc
module spring.boot.starter reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc

error: module spring.data.relational reads package org.springframework.data.jdbc.core.convert from both spring.data.jdbc and spring.data.relational
module spring.jdbc reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc

error: module spring.data.commons reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc
module spring.tx reads package org.springframework.data.jdbc.core.convert from both spring.data.relational and spring.data.jdbc

1 个答案:

答案 0 :(得分:1)

TL; DR -我已经使用split packages Gradle插件解决了in this clone of your project错误mrJar < em> 1


漫长的答案

...我在粗略地解释这些错误的含义...

欢迎来到split packages的世界……

…“拆分软件包”是一个古老的Java术语,其中两个名称相同的软件包存在于不同的库/应用程序中。由于可靠的配置,Java 9不允许在不同的模块中拆分软件包……

该引号来自this blog

...如果您遇到这些(或类似的)问题...

several other Stack Overflow questions证明,拆分包对于任何将其项目构造为JPMS模块的人都是不可避免的。

...您能否说明一下如何解决这些问题?...

回到 TL; DR ,我已经通过应用我建议的插件解决了项目拆分包的问题。 Download and build the demo检查结果。

正如我在该演示文档中提到的那样,Java 14 + 支持将在第二天或第二天添加到该插件中。尽快,我将更新演示并编辑此答案。但是我想而不是等到那时,您(和其他感兴趣的潜伏者)今天可以从版本0.0.16的JDK 13支持中受益

Another solution I recently proposed是Mark Reinhold建议的“ Bridges to the class path”方法的实现。我在评论中提到的数字23采用了这种方法。但是我个人更喜欢插件方法。这样更容易,而且省力。






1 我有很好的权威证明 mrJar 插件正在通过JDK14 +支持进行升级。预计将在接下来的1-2天内宣布发布v0.0.17版。