Skip to content

Setting Up Multiple Interdependent Projects in IntelliJ IDEA

Dave N edited this page Jun 29, 2024 · 3 revisions

Setting Up Multiple Interdependent Projects in IntelliJ IDEA

Setting up multiple interdependent projects in IntelliJ IDEA, especially when they are part of the same repository or depend on each other, requires careful structuring to ensure that changes in one project are reflected in the others. Here’s a step-by-step guide on how to set up your Gradle projects in IntelliJ IDEA to handle dependencies and ensure compatibility with Java 17:

1. Clone the Repositories

If you haven't already cloned the repositories, you can do so directly from IntelliJ IDEA:

  1. Open IntelliJ IDEA.
  2. Select File > New > Project from Version Control.
  3. Enter the repository URL (for example, https://github.com/MegaMek/megamek.git) and choose where to store the project locally.
  4. Repeat for the other repositories (MegaMekLab and MekHQ).

2. Create settings_local.gradle Files

  1. For MegaMekLab:

    • Navigate to the MegaMekLab project directory.
    • Create a file named settings_local.gradle with the following content:
    includeBuild '../megamek'
  2. For MekHQ:

    • Navigate to the MekHQ project directory.
    • Create a file named settings_local.gradle with the following content:
    includeBuild '../megamek'
    includeBuild '../megameklab'

3. Open MegaMek as a Main Project

Since MegaMek is the base project that others depend on, open it first:

  1. Open IntelliJ IDEA, if it’s not already open.
  2. Select File > Open and choose the MegaMek project directory.

4. Attach MegaMekLab and MekHQ as Modules

Since MegaMekLab and MekHQ are dependent on MegaMek, you need to add them as modules:

  1. Add MegaMekLab as a Module:

    • With MegaMek open in IDEA, go to File > New > Module from Existing Sources.
    • Navigate to the directory where you cloned MegaMekLab.
    • Select its build.gradle file and follow the prompts to add it as a module.
    • IntelliJ IDEA will recognize the settings_local.gradle and include the MegaMek build.
  2. Add MekHQ as a Module:

    • Repeat the process for MekHQ:
      • Go to File > New > Module from Existing Sources.
      • Navigate to the directory where you cloned MekHQ.
      • Select its build.gradle file and follow the prompts to add it as a module.
      • IntelliJ IDEA will recognize the settings_local.gradle and include both the MegaMek and MegaMekLab builds.

5. Set Up Module Dependencies

Now, set up the dependencies between these modules:

  1. Go to File > Project Structure.
  2. Under Modules in the left sidebar, click on MegaMekLab, then go to the Dependencies tab.
  3. Click the + button, select Module Dependency, and choose MegaMek.
  4. Similarly, select MekHQ, go to the Dependencies tab, add MegaMek and MegaMekLab as dependencies.

6. Configure Java 17 and Gradle Settings

To ensure everything compiles and runs correctly with Java 17:

  1. Set Java 17:

    • Go to File > Project Structure.
    • Ensure the Project SDK is set to Java 17. If not, configure it to use Java 17.
    • Ensure each module is also set to use Java 17.
  2. Set Gradle JVM:

    • Go to File > Settings (or IntelliJ IDEA > Preferences on macOS).
    • Navigate to Build, Execution, Deployment > Build Tools > Gradle.
    • Set Gradle JVM to Java 17.

7. Commit and Push Changes

If you make changes to project settings that should be shared with other team members, remember to commit these changes back to your repository:

  1. Use the VCS > Commit dialogue to commit your changes.
  2. Push the changes using VCS > Git > Push.

8. Verify Everything Works

Run each application within IDEA to ensure that the dependencies are correctly recognized and there are no compilation issues:

  1. Run MegaMek.
  2. Run MegaMekLab.
  3. Run MekHQ.
Clone this wiki locally