0

I am doing a project to get familiar with Java 9 module system. I intend to use module-info.java files to contain my packages and trim down the jre with jlink. The only dependency in my project is Jsoup. jlink does not support automatic modules so I had to download the source of jsoup, include a module-info.java file and re-package the jar. The jsoup project directory has the following structure after modifications:

JSOUP-PROJECT-DIR
  |__src
  |   |__main
  |       |__java
  |           |__org
  |           |   |__jsoup
  |           |        |
  |           |        ... 
  |           |        ...
  |           |
  |           |__module-info.java
  |
  |__target
        |
        ...
        ...

The module-info.java file has following content:

module org.jsoup {
    requires java.xml;
    exports org.jsoup;
    exports org.jsoup.nodes;
    exports org.jsoup.select;
}

I did a clean compilation and repackaging to get the jar with module-info.class: mvn clean package

Then I added this jar as a maven dependency in my project (replacing the original jsoup-x.x.x.jar with the modified one in local repository inside .m2). My project, that depends on Jsoup, has the standard maven directory structure with module-info.java sitting inside the java directory. The module-info.java of this project contains this:

module org.mediacat {
    requires org.jsoup;
    requires jdk.crypto.ec;
    exports org.mediacat.torrent_engine;
}

IntelliJ gives an error in the first line of my project's module info file,

Module org.mediacat reads package 'org.jsoup' from both 'org.jsoup' and 'org.jsoup'

I don't understand what it's trying to convey. Despite this inspection, when I do mvn clean compile -Dtest=MyTests test, everything works smoothly. I don't get any kind of warning or error. On top of that, I am able to create the custom jre with jlink --module-path target --add-modules java.base,org.mediacat,org.jsoup --output jre (I manually copied the modified jsoup.x.x.x.jar in the target directory of my project). The error highlighted in IntelliJ is super annoying. I'm worried if I am making a mistake. I want to know if I am actually, or it's possibly a bug in IntelliJ (or maybe my project is wrongly configured)?

EDIT: By the way, when the application is ran through a run configuration generated by IntelliJ Idea (by clicking the green run gutter icon where main function is defined), again, the program compiles and runs just fine.

  • Which version of IntelliJ IDEA are you using? – Naman Sep 15 '19 at 18:18
  • @Naman Version 2019.2.2 on Windows 10 64bit environment. –  Sep 16 '19 at 03:29
  • Is it possible to provide the sample project where you experience the issue? Thanks – Olga Klisho Sep 16 '19 at 15:20
  • @OlgaKlisho Sure! I've set up a minimal project to demonstrate the issue: https://drive.google.com/open?id=1qaKbgHTzMSjP_gmTvqy1yr9BZrWjcpP3 The zip contains two projects, one is the sample application and the other is modified jsoup. To reproduce the error, one must manually copy the modified jar to local .m2 repository, replacing the original jsoup.x.x.x.jar there. I know it's not the best way to do things. I intend to change it very soon in my original project. But for now, it serves the purpose well. Thanks! –  Sep 17 '19 at 04:33
  • Seems to be working correct for me with IDEA 2019.3. Please check the project: https://drive.google.com/open?id=14-FW6Z6ZSGUeoI5uV_ZhJVZgeJpDWTl1 – Olga Klisho Sep 22 '19 at 15:32
  • @OlgaKlisho Sent a file access request. –  Sep 23 '19 at 13:16
  • @OlgaKlisho Nope! Still the same error for me: https://imgur.com/a/lFZFZQf Did you replace the jsoup jar file in your local maven repo with the modified, modular one? If yes, can you upload your version of the modified jar (or ideally, the whole project)?! Also, I am using IDEA 2019.2. –  Sep 23 '19 at 13:41
  • It's probably doing that because you had initially tried to use jsoup by downloading it from maven, so intelliJ still hasn't caught on that you now want to use a local dependency – smac89 Oct 30 '19 at 03:32
  • @smac89 If I understand properly you are suspecting that IntelliJ isn't using the jar from local repository? With some confidence I can say that this is not the case because when I replace the modified library jar with the clean one in my local repository the error disappears. –  Oct 30 '19 at 05:00
  • No, I am suspecting that it is using it, but it still has the one it downloaded from maven in memory somewhere and is also referencing that (which may be why it is complaining that there are two jars exporting the same module). I am just purely speculating of course – smac89 Oct 30 '19 at 05:02
  • Although I started ignoring this long ago, I am interested if you can suggest a solution. I did set up a sample project to illustrate the issue so all the project level configurations were overwritten I guess. Don't know what else to try. –  Oct 30 '19 at 05:26

0 Answers0