Reputation: 2511
I'm working on an existing maven-based Java project to support Java Module (JPMS). So far I had no problem defining new modules and their dependencies with files info-module.java, but I still have problems when I try to run unit tests from Eclipse.
Test code follows the usual folder and package scheme for Maven projects: code is inside src/test/java folder and replicates the package structure of application code.
When I try to run a JUnit test case from Eclipse, I receive a lot of errors about missing modules or not visible packages. What I like to do now is running unit test using only Java classpath and ignoring module path. With Maven and Surefire plugin it's pretty straightforward as I can use option useModulePath to ignore module path.
I also know that IntelliJ as an option called 'Do not use --module-path option' which does exactly what I need.
Do you now any equivalent option or workaround for Eclipse to obtain this behavior?
Upvotes: 2
Views: 1088
Reputation: 188
https://docs.oracle.com/javase/9/migrate/toc.htm#JSMIG-GUID-2F61F3A9-0979-46A4-8B49-325BA0EE8B66
Look for the Runtime Option --add-opens and use it to give the reflective access that JUnit or TestNG etc need to the whitebox testing build.
It looks like this will not improve in the short term. Build tools like Gradle have packaged this up to make it less painful.
Upvotes: 1
Reputation: 2511
After some research I've found a workaround which works fine for me. I want to make clear that it's a workaround and it's not something comparable to the Intellij feature I talk about in the question. Basically I filtered file module-info.java in 'Java Build Path' options:
In this way Eclipse ignores module path and uses only the old classpath.
Upvotes: 2