LayerInstantiationException - 两个模块中的软件包许可证有什么解决方案吗?

Hei*_*itx 5 font-awesome java-module java-11 javafx-11

我有三个名为 core、common 和 item 的模块,每个模块都是 Maven 项目的子模块。我正在使用 ServiceLoader 来实现服务方法,并使用 Java 11 和 fontawesomefx 11(最新)。

我没有使用过 Java 的模块系统,所以我不知道我对模块信息文件的处理是否正确。然而,核心和项目模块都需要 fontawesomefx 模块,并且会导致以下错误:

Error occurred during initialization of boot layer
java.lang.LayerInstantiationException: Package license in both module de.jensd.fx.fontawesomefx.materialicons and module de.jensd.fx.fontawesomefx.materialdesignicons
Run Code Online (Sandbox Code Playgroud)

所有子模块的模块信息:

module common {
    requires javafx.graphics;
    requires javafx.controls;
    requires de.jensd.fx.fontawesomefx.commons;
    exports common.abstractions;
    exports common.services;
    exports common.sidebar;
    opens common.services;
}

module core {
    requires common;
    requires javafx.controls;
    requires javafx.fxml;
    requires de.jensd.fx.fontawesomefx.materialdesignicons;
    uses common.services.ISidebarPlugin;
    exports core.ui to javafx.graphics;
    exports core.ui.mainpage to javafx.fxml;
    exports core.ui.sidebar to javafx.fxml;
    opens core.ui.mainpage to javafx.fxml;
    opens core.ui.sidebar to javafx.fxml;
}

module item {
    requires common;
    requires de.jensd.fx.fontawesomefx.materialicons;
    provides common.services.ISidebarPlugin with item.sidebar.ItemSidebarPlugin;
}
Run Code Online (Sandbox Code Playgroud)

如果我删除该provides common.services.ISidebarPlugin with item.sidebar.ItemSidebarPlugin;应用程序,该应用程序可以工作,但没有项目模块,因为 ServiceLoader 不会加载该实现。

vat*_*bub 0

由于我遇到了同样的问题,但是自制的而不是依赖项,所以我会写一个快速答案:

造成此问题的原因是两个模块包含相同的包。重要的是,META-INF在 JAR 中找到的任何文件夹(除了 )都被视为包 - 即使它只是一个license文件夹。就您而言,这似乎是由打包不当的依赖项引起的。

就我而言,如前所述,它是自制的。我有一个插件,可以将许可证信息注入到我的 JAR 中,并且还将其注入到各处的同一位置。因此,我必须为构建的每个模块单独配置插件,以便将其注入到每个模块的不同包中。