簡體   English   中英

了解 JPMS 模塊的錯誤

[英]Understanding errors with JPMS modules

我很難破譯這些錯誤的含義,更不用說開始解決它們了。 我正在嘗試將 java 平台模塊(使用 jdk 14)與一個簡單的“基於 gradle 的多模塊”項目一起使用(使用 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

TL;DR — 我已經使用mrJar Gradle 插件1解決 了您項目克隆中的拆分包錯誤。


冗長的答案

……我很難理解這些錯誤的含義……

歡迎來到拆分包裝的世界……

…“拆分包”是一個古老的 Java 術語,其中兩個具有相同名稱的包存在於不同的庫/應用程序中。 由於配置可靠,Java 9 不允許在不同模塊中拆分包……

那句話來自這個博客

...如果您遇到這些(或類似)問題...

正如其他幾個 Stack Overflow 問題所證明的那樣,拆分包對於將項目構建為 JPMS 模塊的任何人來說都是不可避免的。

……能否請您解釋一下您是如何解決這些問題的?……

回顧TL;DR ,我已經通過應用我建議的插件解決了您項目的拆分包問題。 下載並構建演示以檢查結果。

正如我在該演示的文檔中提到的,Java 14 +支持將在接下來的一兩天內添加到該插件中。 盡快,我將更新演示並編輯此答案。 但是我認為與其等到那時,您(和其他感興趣的潛伏者今天可以從 0.0.16 版的 JDK 13 支持中受益。

我最近提出的另一個解決方案是實施 Mark Reinhold 建議的“ 通往類路徑的橋梁”方法。 我在評論中提到的數字23采用了這種方法。 但我個人更喜歡插件方法。 這要容易得多,而且工作量也少得多。






1確信mrJar插件正在升級以支持JDK14+。 v0.0.17 版本預計將在未來 1-2​​ 天內公布。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM