Module must not contain source root. The root already belongs to module

Answered

This error: Module must not contain source root. The root already belongs to module

Seems to be fairly common. I am trying to reference a jar built from a Github project. This jar can be referenced from an Eclipse project but no Intellij, or i get the above error.

 

https://www.java-forums.org/intellij-idea/95338-unable-load-external-dependencies-intellij-using-maven.html

2
7 comments

Please share a sample project to reproduce the problem.

0

This is the project that the JAR is based off of.

0

I cannot provide you with my entire project:

A. It is too large

B. It is proprietary

0

Try to reproduce it in a smaller project that is a) small b) non-proprietary and share it, otherwise it's hard to tell what is exactly the problem with your configuration.

1

Please see https://www.jetbrains.com/help/idea/2017.1/content-root.html.

Open the Project Structure window (File -> Project Structure...) and remove all the content root entries in each of the modules (select them one at a time and 'x' the content root in the far right pane).  Then you can save your changes.  While at it, select the Problems on the far left if it has a number to its left.  Fix each problem and select OK.  When you rebuild, the content roots may come back, depending on your setup.  In my case, they did, somehow Intellij decided each of my sub-modules needed a content root.  I had added a single content root at the top level thinking that then there would 'be only one'.  After Intellij added the content root for all my submodules, the error came back. To resolve this, I removed the content root at the top level, which contained all of my sub-modules.  So if you have a module that contains sub-modules, do not add a content root at the container level.

4

Chances are, the one giving you this error is one the sub-modules.  you don't need to go through the "nuclear option" :) and just delete the "Source" folders that's been added in the root/parent module.

2

Please sign in to leave a comment.