Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin/IntelliJ Modules with Shared Content Root

I'm working on a project in IntelliJ Idea using Kotlin. I'm trying to create a unit test for a Kotlin class, and I can create the class, except that when I run the test, I get an error that there is no JDK configured. I go into the project structure and change the JDK for the module, but when I click on Apply, I get a message saying that :

Content root "C:\Users\2rtmar\Documents\xproject\xproject\examples\src\main" is defined for modules "xproject-examples-utils_main" and "xproject-examples-java_main". Two modules in a project cannot share the same content root.

Another team member had said that these modules were faulty, and that they couldn't be used, but I'm not using them and still prevent me from running my code. I tried to unmark this module as a sources root, but did not fix the problem. I went as far as to removing the xproject\examples module entirely, but received the same message when trying to set the JDK of my module.

Any help is appreciated!

like image 291
2rtmar Avatar asked May 17 '18 13:05

2rtmar


Video Answer


2 Answers

I got this issue recently. The very first check should be to check if any other module with the same content root is added or not.[you can check this in Project Structure -> Modules]

If YES, remove the other project by clicking on - (minus) button at the top.

like image 175
Diwakar Avatar answered Oct 19 '22 02:10

Diwakar


In my case I was trying to setup a multi-module Gradle project by adding a new module to my root Gradle project.

Despite adding an include ':my-submodule' to my settings.gradle, it was always telling me gradle wrapper not found, because the submodule was kind of outside of the context of the root module.

This however is IntelliJ-specific

When I looked into Right-Click on module -> Open Module Settings - > Modules I was seeing the following hierarchy:

my-root
   -> my-submodule
my-submodule

For whatever reason, IntelliJ has added the new module as a child and as a standalone module, and this caused the issue Two modules cannot have the same content root, as my-root:my-submodule and my-submodule are now both pointing to the same src/main directory.

This is IntelliJ's out of the box behaviour when adding a new submodule, which is in my opinion totally wrong and likely a bug! You cannot even fix it within the module settings

Solution

But I discovered a way to fix it.

  1. Right-click on the module
  2. Load/Unload Modules
  3. Now unload the module that is not below the my-root

After that, there is just one single root pointing at the src directory and the active module is now within the parent's Gradle scope.

I hope Jetbrains fixes these issues. Those problems exist for a while now and are not pleasant to solve.

like image 40
Marian Klühspies Avatar answered Oct 19 '22 01:10

Marian Klühspies