Eclipse complains JUnit in Modular project [message #1803072] |
Thu, 21 February 2019 15:16  |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
Sverre Moe wrote on Thu, 21 February 2019 21:16Doesn'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 #1803166 is a reply to message #1803156] |
Sun, 24 February 2019 09:30   |
Eclipse User |
|
|
|
Stephan Herrmann wrote on Sat, 23 February 2019 16:27Your 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.
|
|
|
|
Powered by
FUDForum. Page generated in 0.06043 seconds