Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does Intellij store the data about which content roots are configured for modules?

If I go to the project structure menu in Intellij, select a module and go to the sources tab, I am able to add a content root to the module which is outside of the project location.

What I am hoping to find out, is where intellij stores this setting. I imagine somewhere there is an xml file which describes what content roots are set up for a module, but I can't find it for the life of me.

Some background:

The problem I am trying to solve is that the project that I'm working on now is very large and very strangely structured (think package names which don't match directory structure) and is compiled using Makefiles. Because of this (and probably some other reasons I haven't worked out yet) if I just import the source as a new project from existing sources Intellij is unable to find most of the classes.

Most of the other developers on the project use a combination of command line and vim, however there is one developer that uses Eclipse. This developer has written a tool which creates multiple Eclipse projects (about 40) from the source code and using the LinkedResources feature Eclipse offers, is able to link it back to the original source location, without having to have anything put in the repository.

I am able to import this eclipse project into Intellij but Intellij is unable to translate or understand the concept of LinkedResources and so the modules and packages that are created in Intellij are empty, but it has managed to find the .class files and decompiles them (I assume because of Eclipse .classpath file), so I can see the decompiled classes for each of the Eclipse projects (which get created as modules in my Intellij project). If I then manually go through the modules and add content roots that match the path specified in the LinkedResource tag in the Eclipse .project file then I am able to find the actual .java files and edit them. Wonderful!

The second part of the problem stems from the company process around using git. Rather than using branches for new feature work, the company I work for uses cloned repos to do feature work. So this means that when I start a new piece of work, I need to clone the repo on the server which hosts git, then clone that locally and commit and push to that repo. This means that I'm unable to set this project up once and leave it alone and just switch around branches, I would need to create the project anew each time I need to switch repos.

The eclipse project gets around this by using script with a sed command to find and replace the correct filepaths in LinkedResources tags in the .project files to point to the different repos when you want to work on different features, Eclipse then updates and points to the new files and when you edit the files you're editing the new remote location.

I want to be able to replicate this by using a sed command (or something similar) to modify the paths of the content roots specified so that I can continue to use Intellij rather than having to use Eclipse. Given that there are 40 or so modules created, it's far too time consuming a task to do manually each time I switch repos.

I'd appreciate any pointers in the right direction, or any other suggestions that might be used to solve this problem. Thanks!

like image 588
Kialandei Avatar asked Feb 01 '26 07:02

Kialandei


1 Answers

If I understood you correctly, you need to set up the source folder of your project. That goes into the .iml (module file) that accompanies your project. Look for the path module.component.content in that XML file.

For instance, a pretty regular module would follow this structure:

<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
    <output url="file://$MODULE_DIR$/target/classes" />
    <output-test url="file://$MODULE_DIR$/target/test-classes" />

    <!-- This is what you're looking for -->
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
      <excludeFolder url="file://$MODULE_DIR$/target" />
      <excludeFolder url="file://$MODULE_DIR$/../jaxrs-container-api/target" />
    </content>
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="library" name="Maven: javax.ws.rs:javax.ws.rs-api:2.0.1" level="project" />
  </component>
</module>
like image 140
Carlos Melo Avatar answered Feb 02 '26 20:02

Carlos Melo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!