sawdust
sawdust copied to clipboard
IntelliJ complains about duplicate module-info.java
I've tried the newest version of IntelliJ EAP (2020.1) and still, IntelliJ complains about the two module-info.java via:
'module-info.java' already exists in the module
Maven compiles just fine though. And I was not able to find any other problems besides these red underlines that indicate errors in IntelliJ. Any ideas about that?
Which IDEA module contains the error?
Every (maven) module with two module-info.java
:
modular-whitebox-patch-compile
modular-blackbox-stereo
I see.
That's why I invented and promoted the module-info.test
work-around as described in https://sormuras.github.io/blog/2018-09-11-testing-in-the-modular-world#white-box-modular-testing-with-extra-java-command-line-options
Caveat: IDEA, Maven Surefire and most other tools don't support module-info.test
, though. Trying together with Robert to convince the Jigsaw-Crew to improve the situation: http://mail.openjdk.java.net/pipermail/jigsaw-dev/2020-February/thread.html#14357
It's actually a shame that there is no proper solution yet. Java 9 is over 2 years old already.
I think I have also a small hack for this. If the test-packages also exist in the main path, one can opens
the packages just to the test engine. For example, in modular-whitebox-path-compile, we can change the module-info.java in the main/java
to:
module foo {
exports foo;
opens foo to org.junit.platform.commons;
requires java.logging;
requires org.junit.jupiter.api;
}
This also works with surefire and the newest versions of junit. Even though this is definetly not a good way to do it.
[...] Even though this is definetly not a good way to do it.
Exactly. I'd go even further and state: that's an absolute no-go!
Don't mess with the main descriptor just for the purpose of testing. The main descriptor is meant to be re-used, potentially published to Maven Central and shall only contain the minimal required API to work properly.
So for now (even two years since java 9), it looks like one should not mess up with Intellij, maven and jigsaw. It seems the best to avoid javas module system until there is a common solution that is supported by intellij, maven surefire, and jigsaw.
Am I right?
It depends and only time will tell.
Jigsaw + Foundation Tools (javac, jar, javadoc, ...) are fine. Of course, there are still bugs within those tools regarding the module system support.
Most "vintage" build tools took and take Java packages as their building blocks -- due to the fact there weren't Java modules around when those tools were created. Some tools (and underlying project models) may adopt, some won't.
Soon, it'll work with IntelliJ's IDEA: https://youtrack.jetbrains.com/issue/IDEA-253066#focus=Comments-27-5173827.0-0