-
Notifications
You must be signed in to change notification settings - Fork 327
Complete Development Environment Setup using IntelliJ Idea
This goes over a complete development environment setup for MegaMek, MegaMekLab, and MekHQ. It assumes you have some familiarity with your operating system of choice. For all three major platforms, you'll need to make sure you have Git and a Java Development Kit already installed. We are currently using Java 17 for development.
- Download and Install IntelliJ IDEA
- Create Accounts and Account Setup
- Git Configuration
- Initialize Git Repositories
- Rename Git Repositories (Optional)
- Download Reference Copies (Recommended)
- Setup Composite Build
- MegaMekLab
- MekHQ
- Save the File Changes
- Setup IDEA
This is currently the preferred IDE for development and the one we'll be going over. We are looking at getting instructions for Eclipse and VS Code as well but will take time. There are certain features of IDEA that make it ideal to ensure compliance with our Coding Style configuration.
Download the installer for your platform and run through the initial setup. Unless you have a paid account, or access to the GitHub Education, use the Community Edition.
On Windows, there are a few changes that we recommend during installation that you make as indicated below in the image.
For Windows users, go ahead and restart. It'll help prevent potential problems later. For all other platforms, carry on.
You're here on GitHub so, if you haven't already, make a GitHub account and create a fork of the three repositories into your account. This can be done by navigating to each one and clicking the Fork
button in the top right of the page. Process should be near instant.
The three repositories are at MegaMek, MegaMekLab, and MekHQ respectfully.
Be sure to also join our Discord so you can converse with the rest of the development team and get any additional help along the way as well as get early insights into what is being worked on.
The follow steps are recommended and may later be enforced. Need to configure Git with your name (can be your user name or actual name, something we can use to identify you in essence) and an email address that is verified by GitHub. These two things allows Git to show that they are verified commits by you.
git config --global user.name "John Doe"
git config --global user.email [email protected]
As an added step, we encourage you to also Sign your commits. This is an extra step that ensures the commits you make really are coming from you as only you'll have the key for it. The instructions for that can be found here
Setup a folder somewhere on your computer to hold your development work. On macOS, if you create a ~/Developer
account you'll get a special icon for it. We suggest a similar path for Linux users as well to keep it in your home folder.
For Windows users, make sure that where you put the folder is NOT managed by OneDrive as it WILL mess things up. We'd suggest at C:\Developer
.
Inside of this Developer
folder, create a folder called MegaMek
to store the three repositories. Whether you wish to contribute to all three or not, we strongly urge you to clone all three as changes in MegaMek or MegaMekLab CAN impact MekHQ and MegaMekLab, and to compile MekHQ you also need MegaMek and MegaMekLab.
Inside this MegaMek
folder, clone the three repositories. If you're using a Git GUI, follow their instructions on how to do that. From a terminal window however, enter the following commands:
git clone https://github.com/JohnDoe/megamek
git clone https://github.com/JohnDoe/megameklab
git clone https://github.com/JohnDoe/mekhq
An optional step that will make updating the repositories easier is to run the following commands which configures the main repositories as upstreams to yours.
cd megamek
git remote add upstream https://github.com/MegaMek/megamek
git fetch --all
git pull upstream master
git push
cd ../megameklab
git remote add upstream https://github.com/MegaMek/megameklab
git fetch --all
git pull upstream master
git push
cd ../mekhq
git remote add upstream https://github.com/MegaMek/mekhq
git fetch --all
git pull upstream master
git push
These commands change into each folder, adds the main repositories as upstream remotes, fetches the latest changes into the current branch, and then pushes then to your fork. If all things go well, there will be no errors.
Before starting work on a new branch, it is advised you update all to the latest revisions which can be done as follows from the parent MegaMek
(not repository) folder:
cd megamek
git checkout master
git pull upstream master
git push
cd ../megameklab
git checkout master
git pull upstream master
git push
cd ../mekhq
git checkout master
git pull upstream master
git push
Go to here and download the latest released version of the MekHQ bundle. These allow one to refer to the previous behavior while coding, and are great for keeping ones test campaign files in. For easier references, it is advisable to store them within the same parent MegaMek
folder.
Load up IDEA and go through the initial Welcome screens. You'll eventually get to a screen similar to this:

Click on Open
and navigate to where you cloned the repositories and open up MekHQ
. You'll get a popup talking about project configurations, select Gradle Project
.

Give it a few minutes to do what it needs to do. It'll import MekHQ, MegaMekLab, and MegaMek for you automatically. Need to make 2 additional changes to ensure you stick closely with our Style Guide. We use an EditorConfig file to enforce most of the settings and this will change from time to time as the Development team tweaks it. Good news is IDEA helps with this by reading in the file for you automatically and will enforce them over local settings.
Under IDEA Settings, the following two things need to be configured if they are different than shown. First is related to Imports:
And the other for Actions on Save:
These two things adjusts the import
styling at the top of the file to unify it across the entire code base and reduce the chance of errors happening due to the wrong Type being imported.
The second thing will do code cleanup on the file you're working on to ensure it matches the Code Style. This helps ensure you are following the established guide to make it easier for everyone.
To ensure everything is setup correctly, need to run the testAll
command from MekHQ. This will perform a cleanAll
for all three projects then run all three tests. If that succeeds, everything is in good order and you're ready to go!
Note: Warnings are to be expected but so long as no errors show up, things are fine.

Updated: 2025-04-04 - rjhancock