Han*_*nes 4 java java-platform-module-system java-module java-11 javafx-11
在module-info.java我得到错误
包“ com.example”从“ javafx.base”和“ javafx.base”两者中读取包“ javafx.beans”。
迁移(从Java 8到Java 11)不仅使我感到沮丧,而且肯定会令我沮丧,这个错误对我没有任何意义。
我的依赖部分build.gradle:
def springFrameworkVersion = '5.1.2.RELEASE'
def hibernateVersion = '5.3.7.Final'
def junitJupiterVersion = '5.3.1'
dependencies {
compile 'org.transentials:cardhouse-commons:1.1.1'
compile 'ch.qos.logback:logback-classic:1.2.3'
compile "org.springframework:spring-context:$springFrameworkVersion"
compile "org.springframework:spring-jdbc:$springFrameworkVersion"
compile "org.springframework:spring-orm:$springFrameworkVersion"
compile "org.hibernate:hibernate-core:$hibernateVersion"
compile 'org.apache.commons:commons-dbcp2:2.5.0'
compile 'org.apache.commons:commons-lang3:3.8.1'
compile 'commons-io:commons-io:2.6'
compile 'com.h2database:h2:1.4.197'
compile 'javax.xml.bind:jaxb-api:2.3.1'
compile 'com.google.guava:guava:27.0-jre'
compile 'org.flywaydb:flyway-core:5.2.1'
compile 'javax.validation:validation-api:2.0.1.Final'
compile "org.openjfx:javafx-base:11:$platform"
compile "org.openjfx:javafx-graphics:11:$platform"
compile "org.openjfx:javafx-controls:11:$platform"
compile "org.openjfx:javafx-fxml:11:$platform"
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.+'
testCompile 'de.saxsys:jfx-testrunner:1.2'
testCompile 'org.apache.commons:commons-text:1.6'
testCompile "org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion"
testCompile "org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion"
testCompile 'org.hamcrest:hamcrest-all:1.3'
}
Run Code Online (Sandbox Code Playgroud)
和module-info.java:
module open.terms.client.jfx {
requires org.transentials.cardhouse.commons;
requires com.google.common;
requires org.apache.commons.lang3;
requires org.hibernate.orm.core;
requires java.persistence;
requires slf4j.api;
requires javafx.graphics;
requires javafx.fxml;
requires java.desktop;
}
Run Code Online (Sandbox Code Playgroud)
有人可以向我解释编译器要告诉我什么吗?
使用所需的依赖关系列表,如果您从中删除了所有必需的模块module-info,则IDE仍会抱怨相同的错误:
模块''从'javafx.base'和'javafx.base'读取包'javafx.beans'
因此,问题不在您的模块信息中,而在您的依赖项中。如果您注释掉所有这些注释(JavaFX注释除外),那么问题就消失了。
这意味着某些依赖项带有一些不必要的JavaFX依赖项。
我设法通过仅注释第一个依赖项来隔离问题:
compile 'org.transentials:cardhouse-commons:1.1.1'
Run Code Online (Sandbox Code Playgroud)
所以问题是为什么会这样,我们如何解决。
如果转到Maven Central存储库, 它将显示依赖项的GitHub存储库,您可以在其中找到build.gradle文件及其module-info。
不出所料,它使用 JavaFX:
compile "org.openjfx:javafx-base:11:$platform"
Run Code Online (Sandbox Code Playgroud)
并且它也在requires javafx.base其module-info中。
当您将这个工件与依赖项javafx.base一起使用时,您将导入它们的导入以及JavaFX依赖项中的导入,并且会发生冲突。
解决问题的最快方法是在构建中进行以下更改:
compile 'org.transentials:cardhouse-commons:1.1.1'
Run Code Online (Sandbox Code Playgroud)
对此:
compile ('org.transentials:cardhouse-commons:1.1.1') {
exclude group: 'org.openjfx'
}
Run Code Online (Sandbox Code Playgroud)
因此您将排除它的JavaFX依赖关系并将使用您的依赖关系。
一个更永久的修复方法是将工件org.transentials:cardhouse-commons的module-info更改为:
`requires transitive javafx.base`
Run Code Online (Sandbox Code Playgroud)
问题应报告给作者。
注意
javafx顺便说一句,您可以使用gradle 插件处理构建中所有相关的JavaFX部分,将其简化为:
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.5'
}
repositories {
mavenCentral()
}
dependencies {
compile ('org.transentials:cardhouse-commons:1.1.1') {
exclude group: 'org.openjfx'
}
compile files('libs/cardhouse-commons-master-1.1.1.jar')
...
compile 'javax.validation:validation-api:2.0.1.Final'
}
javafx {
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
mainClassName = 'open.terms.client.jfx.Main'
Run Code Online (Sandbox Code Playgroud)
该的OpenJFX文档已经在使用这个插件。
| 归档时间: |
|
| 查看次数: |
942 次 |
| 最近记录: |