opening multiple intellij modules in the same project and remembering them on reopen

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.

EclipseIntelliJ
WorkspaceProject
ProjectModule

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

Testing

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.

Intellij from Microsoft JDConf

Speaker: Trisha Gee – @trisha_gee

A note on speaking quickly: this wasn’t specific to Trisha, but she mentioned it. A 25 minute talk doesn’t mean take a 30-45 minute talk and talk faster. It means have less content. Luckily, Trisha could refer to Venkat’s talk and actually have less content.

In any case, I learned new stuff for IntelliJ, so that’s good. And nice seeing two live demos (Venkat and Trisha) in a row.

  • Supports next version of Java (before released)
  • Modern Java is anything in Java 9 or higher because majority still on Java 8
  • Have two options: LTS (currently Java 11) or latest (currently Java 15)
  • Can choose version of Java for project including preview features version for most recent version of Java
  • Showed refactoring to replace reference with “var”.
    • And how to customize so doesn’t warn on every opportunity.
    • Weak warning = gray out each refactoring opportunity.
    • Inlay hints – can turn off hints for specific things like implicit types
    • Won’t allow you do to the refactoring if changes the meaning. (Ex: when would change List<String> to List<Object>
  • Convenience factory methods for collections
    • Offers to replace Collections.unmodifiableXX() with List.of, Set.of(), Map.of
    • Highlight code and alt-enter to see formatting options that apply to that code
    • Java 11 has Collectors.toUnmodifiableList() and Optional.isEmpty()
  • Java 15 – Switch expressions
    • Can refactor existing code to enhanced switch and make shorter
    • Can merge branches
  • Java 15 – Text blocks
    • Can refactor the mess of concatenation and \n into text block
    • Can “inject” javascript or json to validate and autocomplete the embedded text