包'com.example'从'javafx.base'和'javafx.base'读取包'javafx.beans' [英] Package 'com.example' reads package 'javafx.beans' from both 'javafx.base' and 'javafx.base'

查看:210
本文介绍了包'com.example'从'javafx.base'和'javafx.base'读取包'javafx.beans'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

module-info.java中,我得到了错误

包'com.example'从'javafx.base'和'javafx.base'读取包'javafx.beans'.

Package 'com.example' reads package 'javafx.beans' from both 'javafx.base' and 'javafx.base'.

迁移(从Java 8到Java 11)不仅使我感到沮丧,而且肯定地,这个错误对我没有任何意义.

Not only does the migration (Java 8 to Java 11) frustrate me slowly but surely, this error does not make any sense to me.

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'
}

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;
}

有人可以向我解释编译器要通过这个告诉我什么吗?

Can someone explain to me what the compiler wants to tell me by this?

推荐答案

有了必需的依赖项列表,如果从module-info中删除所有必需的模块,IDE仍会抱怨并显示相同的错误:

With the required list of dependencies, if you remove all the required modules from the module-info, the IDE will still complain with the same error:

模块''从'javafx.base'和'javafx.base'读取包'javafx.beans'

Module '' reads package 'javafx.beans' from both 'javafx.base' and 'javafx.base'

因此,问题不在您的模块信息中,而在您的依赖项中.如果您将所有注释都注释掉,除了JavaFX注释,问题就解决了.

So the problem is not in your module-info, but in your dependencies. If you comment out all of them, except the JavaFX ones, the problem is gone.

这意味着某些依赖项带有一些不必要的JavaFX依赖项.

This means that some dependency is carrying some unnecessary JavaFX dependency.

我设法通过仅注释第一个依赖项来隔离问题:

I've managed to isolate the problem by commenting only the first dependency:

compile 'org.transentials:cardhouse-commons:1.1.1'

所以问题是为什么会发生这种情况以及我们如何解决它.

So the question is why is this happening and how can we fix it.

如果您转到Maven Central repo ,则会显示依赖项的GitHub repo ,您可以在其中找到build.gradle文件及其module-info.

If you go to Maven Central repo it shows the GitHub repo of the dependency, where you can find the build.gradle file and its module-info.

如预期的那样,它使用 JavaFX:

As expected, it uses JavaFX:

compile "org.openjfx:javafx-base:11:$platform"

,并且在模块信息.

当您将这个工件与依赖项一起使用时,您将导入其javafx.base导入项以及JavaFX依赖项中的导入项,并且存在冲突.

When you consume this artifact with your dependencies you are importing their javafx.base import, along with yours from your JavaFX dependencies and there is the conflict.

解决问题的最快方法就是在您的构建中进行更改:

The fastest way to solve the issue is just changing this in your build:

compile 'org.transentials:cardhouse-commons:1.1.1'

对此:

compile ('org.transentials:cardhouse-commons:1.1.1') {
    exclude group: 'org.openjfx'
}

因此您将排除它的JavaFX依赖关系并将使用您的依赖关系.

so you will exclude its JavaFX dependencies and will use yours.

一个更永久的修复方法是将工件org.transentials:cardhouse-commons的module-info更改为:

A more permanent fix will be changing the artifact org.transentials:cardhouse-commons's module-info to:

`requires transitive javafx.base`

您可以在transitive 此处中了解使用方法.

You can read about the use of transitive here.

应该向作者报告问题.

注意

顺便说一句,您可以使用javafx gradle 插件来保重构建中所有相关的JavaFX部分,将其简化为:

As an aside, you can use the javafx gradle plugin to take care of all the related JavaFX parts of the build, simplifying it to:

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'

OpenJFX 文档已经使用了此插件.

The OpenJFX docs already make use of this plugin.

这篇关于包'com.example'从'javafx.base'和'javafx.base'读取包'javafx.beans'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆