EJS
EJS

Reputation: 1071

How to import a project with modules and java packages in IntelliJ?

We have a java project with several modules. We use git for versioning and want the developers to be able to chose their own IDE. So we don't push .idea and .iml files with git. This means that developers in IntelliJ needs who clones from git needs to set up the project in IntelliJ as well. However we are having some issues with setting it up. In my own project it works fine and looks like:

Proejct Module (Is this a real module?)
   ⤷ Module A
        ⤷ src
           ⤷ main
               ⤷ java
                   ⤷ Package 1
                   ⤷ Package 2
           ⤷ test
   ⤷ Module B

Before we added packages to the project new developers could just pull from git and open Module P in IntelliJ, then go to project structure and import module from Module A and Module B. However if they try the same thing now IntelliJ tries to make the Modules main and test from Module A.

A workaround we temporarily use for this is to open Module A and B directly as separate IntelliJ projects. If we do this IntelliJ does not try to make modules out of main and test. However this is very inconveniant for us.

How can we fix this?

Upvotes: 0

Views: 2380

Answers (1)

vikingsteve
vikingsteve

Reputation: 40428

It's a good approach to make your source control system "agnostic" about the IDE and not check in .idea, *.iml and equivalent things from other IDE's.

However you really need to use a build control system like maven or gradle.

In my workplace we use maven for all our java projects. It's very simple to define a pom.xml at the root level which defines your modules, and many other things.

When you import a maven project into intellij, all the relevant IntelliJ modules are automatically created for you. In essence, you only need to import the pom.xml and you're good to go.

Otherwise it will be a nightmare to import and create modules every time you check out source from git. Maven isn't perfect but I highly recommend using either maven or gradle.

To define multi-modules from the root pom.xml, make a section like this:

<modules>
    <module>module-A</module>
    <module>module-B</module>
</modules>

And then the pom.xml in both module A and B should define a section referring to the root pom via the <parent> tag.

Upvotes: 1

Related Questions