Free-form IntelliJ Projects
So here I want a ‘free-form project’. I want my content roots to only include source files. I have some SSH and DNS learning I’m doing. I want the content to be completely agnostic of IntelliJ. I am grateful to the pointer given to me by a comment way back in 2010 as to override the content root.
In the diagram below I have my content root in Git living in ~/IdeaProjects/Learning_Using_Containers.


However, I want the metadata to live in ~/intellij_metadata/containers, keeping my source tree clean. (I know, it’s just one of my idiosyncrasies.) Here’s the eventual script that I will run to launch IntelliJ passing the metadata folder as a parameter. The folder ‘~/intellij_metadata/containers’ doesn’t exist – yet.
% cat ~/launch_scripts/launch_containers.sh
/Applications/IntelliJ\ IDEA.app/Contents/MacOS/idea ~/intellij_metadata/containers/ &
Luckily creating the setup for this script is easy enough. Again we launch Intellij ‘fresh’ and create a new project. This time it’s an empty style project.


With this setup, I now create empty folders as modules in my metadata folder. First, we can see that the .idea folder has been created as expected.
% ls -alt ~/intellij_metadata/containers
total 0
drwxr-xr-x 6 jamesbowen staff 192B 22 Aug 14:31 .idea
drwxr-xr-x 3 jamesbowen staff 96B 22 Aug 14:31 .
drwxr-xr-x 18 jamesbowen staff 576B 22 Aug 14:31 ..
Next I create some empty folders for Intellij to import. I’m in the ~/.intellij/containers directory at this point.
% mkdir learn_dns learn_ssh
% ls
learn_dns learn_ssh
I created the folders learn_dns and learn_ssh so you (or me reading this in future) can see the relationships between content root folders and metadata folders. Within the project view, I create a new module from existing sources.


This creates iml modules in the ~/intellij_metadata/containers directory.
containers % ls -R
learn_dns learn_ssh
./learn_dns:
learn_dns.iml
./learn_ssh:
learn_ssh.iml
With these setup, I change the content roots of the project to point to where the source lives. We’ll start with the ~/IdeaProjects/Learning_Using_Containers/learning_dns content root.


Then I remove the old content root – in the right diagram, it’s the one ending containers/learn_dns. See how in the following diagram the module retains the name “learn_dns” from the metadata, but shows the correct content root of “learning_dns”. Finally, we repeat the process for the second module.


Now when I run the launch script, I have a clean separation between source and metadata. For me, that one-off investment was worth it for knowing how to set things up in future. I have got a cleaner workspace that doesn’t grate with me by having the ‘.idea’ directory/iml files there, constantly reducing my mental bandwidth. So a case of the 80-20 principle, and all that.
Conclusion
Hope this helped at least some of you, I’ll be referring to it in a few months when I’ve forgotten this. I’m sure! Please feel free to share this article if it helped you.