com.google.inject包可从多个模块访问

问题描述 投票:0回答:4

我正在尝试将应用程序从Java 8升级到Java 11.0.2。所以这些是我使用Jigsaw模块的第一步!

我的应用程序使用GuiceAssistedinjectThrowingproviders扩展。

这是我目前的module-info.java

`

module com.example.mymodule {

    requires com.google.guice;
    requires com.google.guice.extensions.assistedinject;
    requires com.google.guice.extensions.throwingproviders;

    //...
}


`

该应用程序基于Maven,当我运行mvn package时,我没有错误。但是在Eclipse(2018-12)中,我有这个错误“`com.google.inject包可以从多个模块访问”:

error

enter image description here

我尝试在module-info.java中评论每个必需的模块,但我显然需要其中的三个。

我能做些什么来消除这个错误吗?或者这是一个Eclipse错误?

这是我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>example</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.7</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpmime</artifactId>
            <version>4.5.7</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.8.1</version>
        </dependency>
        <dependency>
            <groupId>commons-validator</groupId>
            <artifactId>commons-validator</artifactId>
            <version>1.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-text</artifactId>
            <version>1.6</version>
        </dependency>
        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.11.3</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.26</version>
        </dependency>

        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <version>4.2.2</version>
        </dependency>
        <dependency>
            <groupId>com.google.inject.extensions</groupId>
            <artifactId>guice-throwingproviders</artifactId>
            <version>4.2.2</version>
        </dependency>
        <dependency>
            <groupId>com.google.inject.extensions</groupId>
            <artifactId>guice-assistedinject</artifactId>
            <version>4.2.2</version>
        </dependency>

    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                    <configuration>
                        <source>11</source>
                        <target>11</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
        </plugins>
    </build>
</project>

这是一个minimal project来重现我的错误。

这里是a video of the issue(为了清晰起见,将在1080P中观看!)。

java eclipse guice jigsaw
4个回答
2
投票

Eclipse使用自己的编译器,在遵循规范时甚至比javac更严格。您需要在module-info中使用com.google.inject包中的不同模块/ Jars。这是某种拆分包的情况,这在JPMS规范中是不允许的。如果在不同模块的相同包中存在实际类,则AFAIK javac仅产生错误,但是eclipse编译器在这里更加挑剔。

有一些解决方案可以解决拆分包问题。如果你没有找到问题得到解决的更新版本的libs(不幸的是,对于今天的大多数依赖项来说不太可能),你可以f.e.将模块合并为一个自定义模块,但这当然不是一个完美的解决方案。

有关该问题的更多背景信息,请参阅Eclipse can't find XML related classes after switching build path to JDK 10https://bugs.openjdk.java.net/browse/JDK-8215739


2
投票

我可以在我的机器上重现错误(相同的Eclipse版本,OpenJDK 11),在Apache NetBeans IDE 10.0上正常工作。

似乎是Eclipse中的一个错误,你应该把它归档为here。您已经有一个重现错误的最小项目,这有很大帮助。


2
投票

您的测试项目已经在4.11的RC2中工作(将于2019年3月20日发布)

您可以在https://download.eclipse.org/eclipse/downloads/drops4/S-4.11RC2-201903070500/下载候选版本


0
投票

通过转到pom.xml中的依赖层次结构来处理这类问题的更好方法,在那里你可以找到重复的jar,有时可能很难找到重复的jar,因为jar本身有pom依赖,而“Dependencies hierarchy”会帮助你处理maven问题`enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.