Search code examples
gitintellij-idea

How to work with multiple modules and git in an IntelliJ Project?


I am working on a microservices project where I have the following modules:

  • Client app
  • Service Module A (e.g. Image processing)
  • Service Module B (e.g. Ecommerce)
  • Service Module C (e.g. Video processing)

So far the client-facing app has a git repository and pulls/pushes fine to the remote repo.

Now I need to put all the service modules into their own git repos and push/pull to their own remote repos.

After adding the remote repos for each module under Git > Manage remotes in IntelliJ Idea, it still only shows the git repo for the Client app. I don't understand how I can independently manage the other modules with git.

I would like to ideally keep all the separate apps and services within one project. I find that easier to manage than creating a new IntelliJ project for each module.

Am I using IntelliJ incorrectly or is there a way around this? Jetbrains published this https://www.jetbrains.com/guide/java/tutorials/creating-a-project-from-github/adding-updating-remotes/ but it doesn't help me.


Solution

  • In order to add multiple related projects to the same IntelliJ IDEA project, you'll need to add them as modules.

    1. In your client project, open the other project(s) from the menu File | New | Module from Existing Sources.
    2. Select the directory in where one of the other projects (for example, Service Model A) is located and click Open.
    3. In the dialog that opens, select Create module from existing sources.
    4. Select the relevant model, like Gradle or Maven, if applicable.

    Check the docs or watch this video for more details.