简体   繁体   中英

Import maven project to Eclipse gives a bunch of "cannot be resolved to a type" errors in for tests

I import https://github.com/pf4j/pf4j to Eclipse 4.27.0 with M2E plugin installed and got bunch of errors in test folder:

Description Resource    Path    Location    Type
AbstractExtensionFinder cannot be resolved  AbstractExtensionFinderTest.java    /pf4j/src/test/java/org/pf4j    line 260    Java Problem
AbstractExtensionFinder cannot be resolved  AbstractExtensionFinderTest.java    /pf4j/src/test/java/org/pf4j    line 273    Java Problem
AbstractExtensionFinder cannot be resolved to a type    AbstractExtensionFinderTest.java    /pf4j/src/test/java/org/pf4j    line 75 Java Problem
AbstractExtensionFinder cannot be resolved to a type    AbstractExtensionFinderTest.java    /pf4j/src/test/java/org/pf4j    line 97 Java Problem
...

Wherein from cmd the project is compiled by maven without errors and Intellij Idea imports the project without errors. What is the problem with Eclipse?

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

UPD I see now, that code in src/main/java are shown as folders not packages, and it is strange, because in test folder it is shown as packages as it should be.

在此处输入图像描述

UPD Java Build Path / Sources seems is ok.

在此处输入图像描述

Several problems with this project in m2e:

  • Parent pom claims maven.compiler.release=1.8 , while child module does "module stuff" (java9+)..which confuses m2e. (, me2 completely:)
  • "complex compilation" in pf4j module

(Current master version) Does the following after every "project import/maven update":

坏的“包含”属性

(This is "too narrow/few" includes,) Which explains eclipse "Problems".

To fix it (temporarily) we can remove these includes:

删除包括

For a permanent fix: pf4j and m2e have to "meet" somehow:)

I propose (herewith):

<profiles>
    <profile>
        <id>j9</id>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <executions>
                        <!-- compile module-info.java for Java 9+ -->
                        <execution>
                            <id>java9-compile</id>
                            <goals>
                                <goal>compile</goal>
                            </goals>
                            <configuration>
                                <release>9</release>
                                <multiReleaseOutput>true</multiReleaseOutput>
                                <includes>
                                    <include>module-info.java</include>
                                </includes>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

...to move the "exotic (to blame) compilation" to a "custom profile".

This enables:

  • graceful m2e-re-import
  • "exotic compilation" via profile

(makes both happy)

For the "demo modules" it is sufficient to "switch off (m2e) workspace resolution"/fix pf4j module;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM