我正在模块化和现有的非模块化应用程序。为了使用Java模块系统让我的生活更轻松,我决定选择一个工作示例https://github.com/beryx-gist/badass-jlink-example-log4j2-javafx它与我的应用程序类似,并添加了我需要的依赖性,使其发挥作用。我从odfdom
开始,我正在使用jOpenDocument
处理许多OpenDocument电子表格,但odfdom
现在看起来更有前景,所以我开始着手。我在运行示例时得到以下错误:
java.lang.module.ResolutionException: Modules maven.core and maven.artifact export package org.apache.maven.artifact.repository to module org.json
当我将以下行添加到buid.gradle
:时,就会发生这种情况
implementation 'org.odftoolkit:odfdom-java:0.10.0'
否则,项目将按预期构建和运行。我应该如何解决这个问题?这是build.gradle
:
plugins {
id 'application'
id 'org.javamodularity.moduleplugin' version '1.8.9'
id 'org.openjfx.javafxplugin' version '0.0.10'
id 'org.beryx.jlink' version "2.24.1"
}
repositories {
mavenCentral()
}
sourceCompatibility = "11"
targetCompatibility = "11"
dependencies {
implementation 'org.apache.logging.log4j:log4j-core:2.11.1' //automatic-module
implementation 'com.google.code.gson:gson:2.9.1' //module
implementation 'org.odftoolkit:odfdom-java:0.10.0' //none
}
javafx {
version = 16
modules = ['javafx.controls']
}
application {
mainClass = "org.openjfx.HelloFX"
mainModule = "hellofx"
}
和module-info.java
:
module hellofx {
requires javafx.controls;
requires org.apache.logging.log4j;
exports org.openjfx;
}
我认为您可能需要将实现的模块名称"org.odftoolkit:odfdom java:0.10.0'"添加到module-info.java中:
requires odfdom.java;
我没有得到你的错误,但得到了很多其他模块错误,例如
.... module reads package org.apache.maven.settings from both maven.settings and maven.core
对我来说,解决方案是在我的build.gradle中添加一些excludes,以便编译:
configurations {
compileOnly.exclude group: 'xerces', module: 'xercesImpl'
// exclude from compile but allow at run time
}
implementation (group: 'org.odftoolkit', name: 'odfdom-java', version: '0.10.0') {
exclude group: 'org.apache.maven', module: 'maven-core'
exclude group: 'org.apache.maven', module: 'maven-plugin-api'
exclude group: 'io.github.git-commit-id', module: 'git-commit-id-plugin-core'
}
我的build.gradle比你的更复杂,我似乎遇到了很多模块冲突,所以这不是同一个问题,但我希望这能为你指明正确的方向。