Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Eclipse complains JUnit in Modular project
Eclipse complains JUnit in Modular project [message #1803072] Thu, 21 February 2019 15:16 Go to next message
Eclipse UserFriend
Doesn't Eclipse now support Java modules fully? I am using Eclipse 2018-12.

Gradle builds and runs the test just fine, but Eclipse complains.
The import org.junit cannot be resolved

Adding the module to module-info.java gets eclipse to stop complaining in my test, but it now complains in the module-info.java
org.junit.jupiter.api cannot be resolved to a module


I don't think it is the right way to add JUnit to module-info.java. If I do it will not compile,
error: module not found: org.junit.jupiter.api


Run as JUnit within Eclipse is not there, but I can choose Run as Gradle Tests and it works.

This is not the only modules problem with Eclipse. With Java 11 and JavaFX 11 now as dependencies, it cannot run an Application from Eclipse.
Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.graphics not found, required by com.company.application
Re: Eclipse complains JUnit in Modular project [message #1803074 is a reply to message #1803072] Thu, 21 February 2019 15:39 Go to previous messageGo to next message
Eclipse UserFriend
Sverre Moe wrote on Thu, 21 February 2019 21:16
Doesn't Eclipse now support Java modules fully? I am using Eclipse 2018-12.


What is your definition of "fully"? :)

We in JDT clearly noticed that take-up of Java 9 is slower, than, e.g. adoption of lambdas was back then. This means, bug reports are coming in with a significant lag after Java 9 GA. Just during the last few weeks several bugs relating to modules have been fixed and fixes are available in milestone builds towards 2019-03.


Quote:

Gradle builds and runs the test just fine, but Eclipse complains.
The import org.junit cannot be resolved

Adding the module to module-info.java gets eclipse to stop complaining in my test, but it now complains in the module-info.java
org.junit.jupiter.api cannot be resolved to a module


I don't think it is the right way to add JUnit to module-info.java. If I do it will not compile,
error: module not found: org.junit.jupiter.api


I don't recall a recent bug report that would cover this, but the first questions here would be: is the source folder containing your tests properly marked as "test"? How is JUnit configured in your project?

Quote:

This is not the only modules problem with Eclipse. With Java 11 and JavaFX 11 now as dependencies, it cannot run an Application from Eclipse.
Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.graphics not found, required by com.company.application


This would be a problem with the command line generated from your launch configuration. You can now inspect this command line with a new button in the launch configuration dialog. Does it show javafx on the module path?

Stephan
Re: Eclipse complains JUnit in Modular project [message #1803114 is a reply to message #1803074] Fri, 22 February 2019 10:52 Go to previous messageGo to next message
Eclipse UserFriend
Stephan Herrmann wrote on Thu, 21 February 2019 15:39
Sverre Moe wrote on Thu, 21 February 2019 21:16
Doesn't Eclipse now support Java modules fully? I am using Eclipse 2018-12.


What is your definition of "fully"? :)


Fully meaning there is not 100% support yet.

When I import a modular project that works fine with gradle, Eclipse complains about JUnit cannot be resolved.
Imported with Gradle Buildship.
Both JDK and Project & External Dependencies are on the Modulepath.

Stephan Herrmann wrote on Thu, 21 February 2019 15:39

Quote:

This is not the only modules problem with Eclipse. With Java 11 and JavaFX 11 now as dependencies, it cannot run an Application from Eclipse.
Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.graphics not found, required by com.company.application


This would be a problem with the command line generated from your launch configuration. You can now inspect this command line with a new button in the launch configuration dialog. Does it show javafx on the module path?

The command line output shows that every dependency is only on the classpath, and nothing on the modulepath.

[Updated on: Fri, 22 February 2019 10:52] by Moderator

Re: Eclipse complains JUnit in Modular project [message #1803117 is a reply to message #1803114] Fri, 22 February 2019 11:44 Go to previous messageGo to next message
Eclipse UserFriend
Sverre Moe wrote on Fri, 22 February 2019 16:52
Stephan Herrmann wrote on Thu, 21 February 2019 15:39
Sverre Moe wrote on Thu, 21 February 2019 21:16
Doesn't Eclipse now support Java modules fully? I am using Eclipse 2018-12.


What is your definition of "fully"? :)


Fully meaning there is not 100% support yet.


After many years in this business I still haven't seen any tool that supports 100% of Java. This language is simply too complex for 100% coverage. This explicitly includes javac. Just saying. We're all trying our best.

Quote:

When I import a modular project that works fine with gradle, Eclipse complains about JUnit cannot be resolved.
Imported with Gradle Buildship.


This should be interesting for the Buildship team. Please report it to them.
Feel free to post the bug number here, so that s.o. from JDT can follow the discussion.

Quote:

Both JDK and Project & External Dependencies are on the Modulepath.
[...]
The command line output shows that every dependency is only on the classpath, and nothing on the modulepath.


That's weird. Perhaps when Buildship resolves its classpath container it doesn't set the "module" attribute on individual resolved entries?

Stephan
Re: Eclipse complains JUnit in Modular project [message #1803154 is a reply to message #1803117] Sat, 23 February 2019 13:30 Go to previous messageGo to next message
Eclipse UserFriend
Stephan Herrmann wrote on Fri, 22 February 2019 11:44

Quote:

When I import a modular project that works fine with gradle, Eclipse complains about JUnit cannot be resolved.
Imported with Gradle Buildship.


This should be interesting for the Buildship team. Please report it to them.
Feel free to post the bug number here, so that s.o. from JDT can follow the discussion.

Well the same applies for projects not using Buildship.

Adding to module-info.java "requires org.junit.jupiter.api;".
Makes Eclipse shut up about JUnit cannot be resolved in my test classes,
but it now complains about my module-info.java with "org.junit.jupiter.api cannot be resolved to a module".
Anyway, having this in module-info.java is wrong anyway. It will not compile the java sources if JUnit is there as a require.

[Updated on: Sat, 23 February 2019 13:31] by Moderator

Re: Eclipse complains JUnit in Modular project [message #1803156 is a reply to message #1803154] Sat, 23 February 2019 16:27 Go to previous messageGo to next message
Eclipse UserFriend
Your answer takes us back to some of my first questions:
Quote:
... is the source folder containing your tests properly marked as "test"? How is JUnit configured in your project?


FWIW, I just created a fresh Java 11 project, created a test source folder marked as "Contains test sources: Yes".
Then I used the wizard to create a fresh JUnit 5 test, which proposed to add the JUnit library to the project, which I confirmed.
From here all can be resolved properly.
FYI, this is the .classpath I ended up with:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
		<attributes>
			<attribute name="module" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="src" path="src"/>
	<classpathentry kind="src" output="test-bin" path="test-src">
		<attributes>
			<attribute name="test" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
	<classpathentry kind="output" path="bin"/>
</classpath>



Re: Eclipse complains JUnit in Modular project [message #1803166 is a reply to message #1803156] Sun, 24 February 2019 09:30 Go to previous messageGo to next message
Eclipse UserFriend
Stephan Herrmann wrote on Sat, 23 February 2019 16:27
Your answer takes us back to some of my first questions:
Quote:
... is the source folder containing your tests properly marked as "test"? How is JUnit configured in your project?


FWIW, I just created a fresh Java 11 project, created a test source folder marked as "Contains test sources: Yes".
Then I used the wizard to create a fresh JUnit 5 test, which proposed to add the JUnit library to the project, which I confirmed.
From here all can be resolved properly.
FYI, this is the .classpath I ended up with:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
		<attributes>
			<attribute name="module" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="src" path="src"/>
	<classpathentry kind="src" output="test-bin" path="test-src">
		<attributes>
			<attribute name="test" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
	<classpathentry kind="output" path="bin"/>
</classpath>



Using the maven/gradle convention for directory structure:
src/main/java
src/main/resources
src/test/java
src/test/resources

This is my .classpath that was created by Gradle Buildship
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
        <classpathentry kind="src" output="bin/main" path="src/main/java">
                <attributes>
                        <attribute name="gradle_scope" value="main"/>
                        <attribute name="gradle_used_by_scope" value="main,test"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="src" output="bin/main" path="src/main/resources">
                <attributes>
                        <attribute name="gradle_scope" value="main"/>
                        <attribute name="gradle_used_by_scope" value="main,test"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="src" output="bin/test" path="src/test/java">
                <attributes>
                        <attribute name="gradle_scope" value="test"/>
                        <attribute name="gradle_used_by_scope" value="test"/>
                        <attribute name="test" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="src" output="bin/test" path="src/test/resources">
                <attributes>
                        <attribute name="gradle_scope" value="test"/>
                        <attribute name="gradle_used_by_scope" value="test"/>
                        <attribute name="test" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/"/>
        <classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
        <classpathentry kind="output" path="build"/>
</classpath>


If I move the JUnit dependencies to classpath instead of modulepath, then it does no longer complain. I have always moved them to modulepath, but considering that the tests are not part of the module it may make sense they should be on the classpath.
Re: Eclipse complains JUnit in Modular project [message #1803175 is a reply to message #1803166] Sun, 24 February 2019 14:28 Go to previous message
Eclipse UserFriend
It seems the missing test attribute is known for Eclipse Buildship
https://github.com/eclipse/buildship/issues/689
Previous Topic:Eclipse builds .jars that misbehave
Next Topic:Strange Math error for multiple operators on one line and no expression evaluation
Goto Forum:
  


Current Time: Mon Aug 25 13:58:35 EDT 2025

Powered by FUDForum. Page generated in 0.05005 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top