0

I am trying to make use of modules and gradle subprojects and either receive compile time errors or complaints from IntelliJ. My project structure is as follows:

Root
- settings.gradle
- core
  - build.gradle
- desktop
  - build.gradle
  - src/main/java/module-info.java

The desktop build.gradle file as a requirement on core as:

dependencies {
  implementation project(":core")
}

There is no reference to the "core" project in the module-info.java files.

In this configuration, IntelliJ doesn't like usage of classes from the "core" project in the "desktop" project (I see a lot of red), but running gradlew.bat desktop:run works with no issues. Bug with IntelliJ? I am using microsoft's openjdk, but hopefully that doesn't matter.

My best attempt to fix this, was to add a module-info.java file to the core project as well and reference the core project in the desktop project's module-info.java file. Unfortunately this configuration, while making IntelliJ happy, renders me unable to run the desktop from command line anymore. I get errors about the core project being unable to find required modules that are the exact same as the required modules I pull in for the desktop module. I think this might be an error on my part, but I'm not sure how or what to do to fix it.

Would appreciate any insight.

P.S. Of these issues, I think I would prefer to get IntelliJ working with the first setup, because I intend to have this core library be shared between the desktop project and an android project, and while I haven't looked into it yet, I am not sure Android supports new java modules?

user2635874
  • 49
  • 1
  • 1

1 Answers1

0

I think terminal should be the first priority. If your original setup made it compiled successfully under terminal, then there is no problem in your project. Do not add extra files for just making the IDE happy.

There's still something you can do. The first step is compiling your project successfully under terminal. This step downloads all the necessary dependencies before IntelliJ, reducing the problem scope to IntelliJ's linking and indexing. Then there are some options:

  1. In the Gradle tool window, click the top-left button Refresh all Gradle projects.
  2. Delete all the .idea folders in your project. Then open the root folder of your project via UI or CLI.
  3. Click the invalidate caches/restart in the main menu.

You can also also create a new Gradle multi-module project with command gradle init, and open it with IntelliJ. It should be analyzed by IntelliJ normally. Then you can compare its project structure with yours. Maybe there's something different.

Hope these steps could help you.

chehsunliu
  • 1,559
  • 1
  • 12
  • 22
  • Afraid none of those worked. Interestingly creating a new multi-module gradle project is creating a whole different set of problems for me. I can't seem to reproduce my issue with a new project... In my project (for some reason) the terminal build is happy with no reference to the subproject in the module-info.java, but in every new gradle project I've tried to setup to duplicate, I can't even run on terminal unless I add a reference to the jar name in the module-info.java (which intelliJ still doesn't like). Maybe unnamed module vs automatic module for some reason? – user2635874 Mar 17 '22 at 03:37