1

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?

enter image description here

enter image description here

enter image description here

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.

enter image description here

UPD Java Build Path / Sources seems is ok.

enter image description here

sdorof
  • 525
  • 6
  • 21
  • The m2e plugin is built-in, so why you tell it's installed? In the second screenshot, the errors are shown in the test code. Did you run the tests in the Maven build (I cannot see it in the third screenshot whether you did)? Does running Maven from inside of Eclipse work? What happens when you delete `pf4j/src/main/java/module-info.java`, right-click the project and choose _Maven > Update Project..._? – howlger Jun 02 '23 at 06:45
  • I say that the m2e plugin is present in the Eclipse, nothing more. Yes, errors are in the test code and in the subprojects. Yes, I run the tests in the Maven buiild (from cmd it run properly, from Eclipse "Run As -> Maven test" they gives bunch errors. If I run Maven > Update Project and/or delete module-info.java nothing new happens, as before there are the bunch of errors. But 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 (I added a new scrinshot of this). – sdorof Jun 02 '23 at 16:11
  • There is also a `target/generated-sources/java-templates`. Could you please explain by what it is generated and whether its sources should be instead or in addition to `src/main/java`. Currently, the Java files in `src/main/java` seems to be filtered out (see _Project > Properties: Java Build Path_, tab _Source_). – howlger Jun 02 '23 at 21:21
  • I don't know how it is generated ```target/generated-sources/java-templates```, but seems with Java Build path / Sources is ok, I updated the post with screenshot. – sdorof Jun 02 '23 at 22:00
  • _Java Build Path_, tab _Source_ looks wrong to me. The first source folder has the subnode `Included: module-info.java` instead of `Included: (All)`. – howlger Jun 02 '23 at 22:25

1 Answers1

0

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":

bad "Included" property

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

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

removed 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;)

xerx593
  • 12,237
  • 5
  • 33
  • 64