Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

m2e removes junit and test classpath entries on eclipise-plugin project (regression) #1776

Open
Liam-Jackson-QAS opened this issue Jun 4, 2024 · 6 comments

Comments

@Liam-Jackson-QAS
Copy link

Given a project with the eclipse-plugin packaging in pom.xml and a .classpath file like:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
                <attributes>
                        <attribute name="module" value="true"/>
                        <attribute name="maven.pomderived" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
        <classpathentry kind="lib" path="libs/org.freemarker_2.3.22.v20160210-1233.jar"/>
        <classpathentry kind="src" output="bin" path="src">
                <attributes>
                        <attribute name="optional" value="true"/>
                        <attribute name="maven.pomderived" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="src" output="target/test-classes" path="junit/test/java">
                <attributes>
                        <attribute name="test" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
                <attributes>
                        <attribute name="maven.pomderived" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
        <classpathentry kind="output" path="bin"/>
</classpath>

When doing Maven->Update Project... the classpathentry for junit/test/java and the one for "org.eclipse.jdt.junit.JUNIT_CONTAINER/5" are removed from the file. The custom lib path is retained.

These entries are required to be retained for being able to run the junit tests for the project within the eclipse IDE.

No changes to the pom.xml seem to help (e.g. defining surefire pluginManagement, testSourceDirectory entries, etc).

This did not occur in eclipse 4.24 (m2e 1.20) but does occur since updating to eclipse 4.30 (m2e 2.4.200). Issue is still present in m2e 2.6.1 / m2e PDE 2.3.2.

@treilhes
Copy link
Contributor

treilhes commented Oct 13, 2024

Hello @Liam-Jackson-QAS,
This issue is pretty old and i think you did find a answer since then.

But for others, be aware that mixing maven and eclipse declared libraries isn't the way to go.
Maven is here to handle the dependencies, so in this case junit5 and freemarker dependencies mustn't be declared using eclipse build path but must be declared inside your pom.xml

If you realy need to declare local jar as a dependency you still need to declare a dependency inside your pom.xml file but using a "system" scope

@Liam-Jackson-QAS
Copy link
Author

Hi @treilhes, thanks for the reply. We are still facing this as an issue unfortunately.

The issue is that the junit/test/java classpath entry is removed by Maven->Update Projects... this means inside eclipse this directory becomes a normal directory and the unit tests cannot be run from within the IDE by right-click->Run As->Junit Test (and other issues relating to indexing) which was working in eclipse 4.24 (m2e 1.20).

We already have junit and other dependencies inside the pom.xml. I have tried removing the other classpath entries as you suggest (they are likely only there for legacy reasons) but the junit/test/java classpath entry is still removed by Maven->Update Projects...

@Liam-Jackson-QAS
Copy link
Author

@treilhes
Copy link
Contributor

Hi @Liam-Jackson-QAS

./junit/test/java is not part of the standard convention used by maven so you need to register it as a test source folder into your project

What about moving your tests where maven expects them ./src/test/java ?

If you need an additional folder you can register it using the builder helper plugin:

<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>3.6.0</version>
        <executions>
          <execution>
            <id>add-test-source</id>
            <phase>generate-test-sources</phase>
            <goals>
              <goal>add-test-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>junit/test/java</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>

In fact, i don't see any issues here only misconfiguration

@Liam-Jackson-QAS
Copy link
Author

Hi, Thanks again.

The build testSourceDirectory and testOutputDirectory are already correct in the pom.

We have already tried using the build helper plugin exactly as suggested, but it does not work. The classpath entry is still removed by m2e.

I believe we cannot use src/test/java because due to being a long running "eclipse-plugin" tycho/PDE project, our source package directories e.g. com/foo/bar live directly under src, not in the typical src/main/java.

@treilhes
Copy link
Contributor

Hello @Liam-Jackson-QAS
If you have a specific setup maybe the way to go would be to share some simplified project but still exhibiting the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants