sawdust icon indicating copy to clipboard operation
sawdust copied to clipboard

IntelliJ complains about duplicate module-info.java

Open AndreG-P opened this issue 5 years ago • 8 comments

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?

AndreG-P avatar Feb 20 '20 11:02 AndreG-P

Which IDEA module contains the error?

sormuras avatar Feb 20 '20 12:02 sormuras

Every (maven) module with two module-info.java: modular-whitebox-patch-compile modular-blackbox-stereo

AndreG-P avatar Feb 20 '20 17:02 AndreG-P

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

sormuras avatar Feb 21 '20 06:02 sormuras

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.

AndreG-P avatar Feb 21 '20 08:02 AndreG-P

[...] 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.

sormuras avatar Feb 21 '20 11:02 sormuras

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?

AndreG-P avatar Feb 23 '20 05:02 AndreG-P

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.

sormuras avatar Feb 23 '20 08:02 sormuras

Soon, it'll work with IntelliJ's IDEA: https://youtrack.jetbrains.com/issue/IDEA-253066#focus=Comments-27-5173827.0-0

sormuras avatar Sep 07 '21 12:09 sormuras