eso
eso

Reputation: 88

How to solve multi-project build problems in IntelliJ IDEA

When opening directories that contain multiple Java projects with IntelliJ IDEA I regularly encounter build problems that cannot be solved with the built-in mechanisms (build tool reload or Invalidate Caches menu item). They typically occur after structural changes like refactoring or changing dependencies, both with Maven and Gradle as the build tools.

The effect of the problem is that new or changed dependencies are not recognized or that some projects in the monorepo are no longer recognized by IDEA. In the case of library projects that will cause build errors in all dependent projects.

I have found a manual fix for this which I will provide as my own answer but maybe someone can provide a better solution.

Upvotes: 1

Views: 1808

Answers (2)

eso
eso

Reputation: 88

A possible solution to this is to manually delete IDEAs build tool cache. To do so first quit IDEA, than delete the corresponding project directory (named .) from the following location (I recommend to backup first):

On Unix: ~/.cache/JetBrains/IntelliJIdea<idea-version>/external_build_system

On Windows: <user-home>\AppData\Local\JetBrains\IntelliJIdea<idea-version>\external_build_system

On Mac OS: ~/Library/Caches/JetBrains/IntelliJIdea<idea-version>/external_build_system

When restarting IDEA it should re-scan the project correctly. At least in my case this has always worked so far.

Upvotes: 1

Max Daroshchanka
Max Daroshchanka

Reputation: 2968

This offtenly works for me:

1 In master project pom I just commenting lines which defines submodules.

2 Then I'm waiting when IDEA will suggest to exclude subprojects. After this action submodule directories will be displayed just like some external file directories, not like a project.

3 Then I uncomment the lines in pom and wait when IDEA will add subprojects again.

4 After this action I select rebuild project in Build section and it works.

I've tested this with maven projects, hope should work for gradle too.


But I agree, sometimes we have to combine this with invalidating caches or just project reopen, or deleting .idea directories.

Upvotes: 0

Related Questions