了解使用JPMS模块时的错误

huangapple go评论70阅读模式
英文:

Understanding errors with JPMS modules

问题

我正在努力解释这些错误的含义,更不用说开始解决它们了。我正在尝试在一个简单的“基于Gradle的多模块”项目中使用Java平台模块(使用jdk 14),该项目使用了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(IntelliJ)非常友好地给了我导出/需要哪些模块的提示,一切看起来都很好,直到我尝试编译。

我在这里包含了项目的Git存储库链接 - https://github.com/m41na/todo-modules-demo

如果您遇到了这些(或类似的)问题,是否可以请您详细说明您是如何解决它们的?

错误信息中涉及了模块依赖冲突,这可能是因为多个模块同时引用了相同的包。您可以尝试以下解决方法之一:

  1. 调整模块依赖关系: 确保每个模块的module-info.java文件正确定义了它所依赖的模块,并且没有重复导入相同的包。

  2. 模块重新组织: 考虑将项目的模块重新组织,以减少模块之间的依赖关系。这可以通过将某些功能拆分到单独的模块中来实现。

  3. 升级依赖版本: 检查您的项目依赖项是否使用了与Spring Data JDBC相关的不同版本。尝试将这些依赖项的版本升级到兼容的版本。

  4. 排除依赖项: 如果有必要,您可以使用Gradle的exclude语句来排除冲突的依赖项,以确保每个模块使用正确的依赖项版本。

请根据具体情况尝试这些方法,以解决模块依赖冲突的问题。希望这些建议能帮助您解决问题。

英文:

I am having a rough time deciphering what these errors mean, let alone even begin to resolve them. I am trying to use java platform modules (using jdk 14) with a simple "gradle-based, multi-module" project (everything works perfectly fine with jdk 8). The project makes use of spring-boot and spring-data-jdbc. Actually my core dependencies are

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'

While I was adding module-info.java to each project source root, my IDE (intellJ) was very kind to give me hints of what modules to export/require, and all looked good until I tred to compile.

I am including a git repo link here to the project that's th topic of this question - https://github.com/m41na/todo-modules-demo

If you have come across these (or similar) issues, could you please shed some light on how you were able to resolve them?

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

得分: 1

TL;DR — 我使用 mrJar Gradle 插件<sup>1</sup> 在 这个克隆的项目中 解决了您项目中的分割包错误。


冗长的答案

> „…我很难理解这些错误的含义…

欢迎来到分割包的世界…

>> „…'分割包' 是一个旧的 Java 术语,指的是两个具有相同名称的包存在于不同的库/应用中。由于可靠的配置原因,Java 9 不允许不同模块中存在分割包…

这句话来自这篇博文

> „…如果您遇到了这些(或类似的)问题…

正如其他几个 Stack Overflow 问题 所证明的,对于将项目结构化为 JPMS 模块的任何人来说,分割包都是不可避免的。

> „…您能否解释一下您是如何解决这些问题的?…

回顾一下 TL;DR,我通过应用我提出的插件解决了您项目中的分割包问题。下载和构建演示 以查看结果。

正如我在那个演示的文档中提到的,插件将在未来一两天内添加对 Java 14<sup>+</sup> 的支持。一旦添加完成,我将更新演示并编辑这个答案。但我觉得与其等到那时,您(和其他感兴趣的人)今天就可以从版本 0.0.16 的 JDK 13 支持中受益。

我最近提出的另一个解决方案 是 Mark Reinhold 建议的「通往类路径的桥梁」方法的实现。我在评论中提到的 23 採用了这种方法。但就个人而言,我更喜欢插件方法。它更加简便,付出的努力也更少。

<br />
<br />
<br />
<br />


<sup><sup><em>1</em></sup>&nbsp;<sup>我有足够的权威信息证实,mrJar 插件正在进行升级,以支持 JDK 14+。预计将在接下来的 1-2 天内宣布 v0.0.17 的发布。</sup>

英文:

TL;DR — I've solved your split packages errors in this clone of your project using the mrJar Gradle plugin<sup>1</sup>.


The long-winded answer

> „…I am having a rough time deciphering what these errors mean…

Welcome to the world of split packages

>> „…'Split packages' is an old Java term where two packages having the same name exist in different libraries/applications. Java 9 does not allow split packages in different modules for the reason of the reliable configuration…

That quote's from this blog.

> „…If you have come across these (or similar) issues…

As several other Stack Overflow questions attest, split packages are an inevitability for anybody structuring their projects as JPMS modules.

> „…could you please shed some light on how you were able to resolve them?…

Referring back to the TL;DR, I've resolved your project's split packages issue by applying the plugin I proposed. Download and build the demo to examine the results.

As I mention in that demo's documentation, Java 14<sup>+</sup> support will be added to that plugin within the next day or two. As soon as it is, I will update the demo and edit this answer. But I figured rather than wait until then, you (and other interested lurkers) could benefit today from version 0.0.16's JDK 13 support.

Another solution I recently proposed is an implementation of Mark Reinhold's suggested „Bridges to the class path“ approach. Numbers 2 and 3 that I mentioned in the comments take that approach. But personally I prefer the plugin approach. It's a lot easier and is way less effort.

<br />
<br />
<br />
<br />


<sup><sup><em>1</em></sup></sup>&nbsp;<sup>I&nbsp;have&nbsp;it&nbsp;on&nbsp;good&nbsp;authority&nbsp;that&nbsp;the&nbsp;mrJar&nbsp;plugin&nbsp;is&nbsp;in&nbsp;the&nbsp;process&nbsp;of&nbsp;being&nbsp;upgraded&nbsp;with&nbsp;JDK14+&nbsp;support.&nbsp;Release&nbsp;of&nbsp;v0.0.17&nbsp;is&nbsp;expected&nbsp;to&nbsp;be&nbsp;announced&nbsp;within&nbsp;the&nbsp;next&nbsp;1-2&nbsp;days.</sup>

huangapple
  • 本文由 发表于 2020年9月26日 07:57:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/64072627.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定