Setting Up Multiple Interdependent Projects in IntelliJ IDEA - MegaMek/megamek GitHub Wiki
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:
- Open IntelliJ IDEA.
- Select File > New > Project from Version Control.
- Enter the repository URL (for example,
https://github.com/MegaMek/megamek.git
) and choose where to store the project locally. - Repeat for the other repositories (MegaMekLab and MekHQ).
settings_local.gradle
Files
2. Create -
For MegaMekLab:
- Navigate to the MegaMekLab project directory.
- Create a file named
settings_local.gradle
with the following content:
includeBuild '../megamek'
-
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:
- Open IntelliJ IDEA, if it’s not already open.
- 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:
-
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.
-
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.
- Repeat the process for MekHQ:
5. Set Up Module Dependencies
Now, set up the dependencies between these modules:
- Go to File > Project Structure.
- Under Modules in the left sidebar, click on MegaMekLab, then go to the Dependencies tab.
- Click the + button, select Module Dependency, and choose MegaMek.
- 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:
-
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.
-
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:
- Use the VCS > Commit dialogue to commit your changes.
- 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:
- Run MegaMek.
- Run MegaMekLab.
- Run MekHQ.