Gangmax Blog

Problem: Open Gradle Project with Multiple Subprojects in IntelliJ IDEA

Today I met a strange issue when I was opening a Gradle project with multiple subprojects in IntelliJ IDEA.

First, after I clone the code from Github, as the “build.gradle” file shows, I run the following command to create IDEA project files:

1
2
gradle cleanIdea
gradle idea

They work properly. And the IDEA project files(both the root project and the subprojects) are created successfully.

But the problem is, when I open this project in IDEA, IDEA cannot recognize the project structure, which means no source code navigation, no libraries downloaded.

I cannot find anything wrong.

After a while, I read this and this.

Then I realize the problem might be caused by “one of the sub-project has the same name as the root project directory“. So I update the “build.gradle” file:

1
2
3
4
5
6
7
8
9
10
11
12
{
...

idea {
module {
// Add the following line to give an explict root project name, rather than
// the default one as the root directory name "yarn-submitter", which has
// duplicated name as one of its sub-project.
name = 'yarn-submitter-parent'
}
}
}

After that, IDEA can open the whole project properly.

The lesson learn here is, never use one name for two different things. And I don’t know why they are named so. I also think IDEA should have a better warning or error message for such problem, instead of showing nothing.

Comments