This is the number one problem that has prevented me from using IntelliJ more and I finally know how to do it. (I’ve known how to open multiple modules for over a year. What I learned yesterday at the IntelliJ 20th anniversary conference was how to reopen that same set)
Note about terminology to Eclipse users
If your primary IDE is Eclipse, keep this difference in terminology in mind as you read this.
Step 1: Create a dummy/grouping project
Create a new project. This project’s purpose is to contain the modules you want together and give it a distinct name. I’ve been keeping them in an IntelliJ folder in my home directory to avoid confusion. (Most of my stuff is under the git folder in my home directory). The idea of keeping them separate is so I know there’s not code in there.
Step 2: Add your modules
There are several ways of adding modules. Any of them are fine. I find the fastest for repeated adds is:
- File > Project Structure > Modules
- Click “+”
- Choose “Import module”
- Navigate to the build file (ex pom.xml) or .iml file for generic projects
Step 3: Rename the project (if needed)
On rare occasions, I noticed the project name got my first module name. I couldn’t reproduce this, but started double checking. This name is what will show up in your recents list.
- File > Project Structure > Project
- Enter a new name if needed
File > Open Recents and open another project. Then File > Open Recents and open this project. Admire how all your modules are back!
Seeing the modules on disk for the curious
In the dummy project, the .idea directory has a misc.xml file. I was told it contains all the modules. And it did when I tested on Windows
<list> <option value="$USER_HOME$/git/myProj/pom.xml" /> <option value="$USER_HOME$/git/myProj2/pom.xml" /> </list>
When I tested on Mac, modules.xml had this info
<modules> <module fileurl="file://$USER_HOME$/git/myProj.xml" filepath="$USER_HOME$/git/myProj.xml" /> <module fileurl="file://$USER_HOME$/git/myProj2.xml" filepath="$USER_HOME$/git/myProj2.xml" /> </modules>
And a note about “you are doing it wrong”
I am an Eclipse power user and an IntelliJ competent user. What holds me back is not using IntelliJ more at work because of not knowing how to do this. While I don’t want to replace my usage, I do want to be an IntelliJ power user and use Eclipse enough to not lose my skills! I think this is the thing that will do it!
When I’ve tried to find out how to add multiple modules and have them remembered multiple times in the past, I was told that I was “using IntelliJ wrong” and should have one project that I focus on. (I work on many sets of small related projects; that model doesn’t work for me.)
Yesterday, someone attempted to tell me that I should have one big project that I focus on at a time. (aka my problem doesn’t exist.) After explaining what I do, another user said he does that I do. The first user said something about religion. That seems like just it. There’s multiple religions. It’s fine to be passionate and a true believer in yours. But as part of society, accepting that other people believe differently is part of life.