How to compile Mindustry step by step - Timmeey86/Mindustry GitHub Wiki

This article is intended for developers who want to compile mindustry on their own, but don't know much about Git, Gradle or IntelliJ IDEA. If you know about these things, the information in the readme is probably sufficient for you. This guide is written for Windows. If you are using any Unix distribution, you probably know how to adapt this to your world.

Prerequesites

You need to have the following things installed (they are pretty standard for open source Java projects):

Additionally, a GitHub account is highly recommended. This guide will assume you have one.

Getting a local copy of the source code

  1. After logging in to GitHub, go to https://github.com/Anuken/Mindustry and click the "Fork" button in the top-right corner.
  2. Click on "Clone or download" and copy the link
  3. In Windows explorer, right-click a folder which shall get a subfolder with the Mindustry code and select "Git GUI Here" in the context menu. (Yes, it's possible through the command line, too, but this won't be described here).
  4. Click "Clone Existing Repository",enter the cloned link (should end with Mindustry.git) as source location and "Mindustry" as target directory and then click "Clone".
  5. Wait for like 5 minutes. Unfortunately, you currently don't seem to get any progress in the GUI.
  6. Close the Git GUI.

Setting up your repository clone

In order to properly work with the repository in future, there are a couple of things to do.

  1. Open the Git shell / command line / terminal at your repository clone (i.e. the "Mindustry" folder) and type
    git remote -v.
    You will usually get output like this:
    origin https://github.com/YourGitHubName/Mindustry.git (fetch)
    origin https://github.com/YourGitHubName/Mindustry.git (push)
  2. This basically means, in your git commands, you can refer to your Fork of Mindustry as "origin", and this is possible for fetching from and pushing to the online repository. However, sometimes we want to pull updates from the original repository into our own (this won't be automatic). This means we need to add another remote to the original repository. Usually, people call this upstream. We do this with the command
    git remote add upstream https://github.com/Anuken/Mindustry.git
  3. Type git remote -v again and check the output. You will see that git now knows about both origin and upstream.
  4. To test it, we can try pulling from the original repository:
    git pull upstream master
    This means we will pull the master branch of the upstream repository into the currently checked out branch (which is master since we did not change it). Dependent on if someone changed the original branch between the creation of your fork and right now, you will either get an Already up to date. message or some command line spam.
  5. Our local clone of the origin repository now contains the most recent changes of the upstream repository, but origin (your fork on Github) does not contain these changes (if any). In order to get them there, you need to do
    git push origin master
    This basically means you push your current branch into the master branch of the originrepository. If there were no changes, you'll get an Everything up-to-date message, but at least now you know how stuff works.
  6. Note that usually, you won't work in the master branch, but in a branch you created for your own changes, but now you know how the get the code Anuke currently has in their master branch.

Getting the code of a certain tag

As long as you are on the master branch, you might have an unstable version. If you rather want to compile a stable one, you usually want to check out a tag instead. The most recent one can be found out from https://github.com/Anuken/Mindustry/tags. For example, if you want to check out the v58 tag, do git checkout tags/v58, and git will switch your local clone to that tag. You will end up in a detached HEAD state, but you can ignore this. Just know that you won't be able to do any changes to the tag (That's what a tag is for - a fixed version of the code).

Creating a branch for changes

There are a lot of awesome git tutorials in the internet, just google a bit and use git help commands. Here is an example for the lazy ones

Compiling the code

  1. Open IntelliJ IDEA. In the welcome screen, select Import Project.
  2. Navigate to your Mindustry clone and select the build.gradle file in the root directory, then press OK.
  3. Check auto-import and press OK again. Gradle will start loading stuff in background. This may take a while when done the first time.
  4. In IntelliJ IDEA, select Run->Edit Configurations.
  5. Select the + icon and select Gradle.
  6. Set the Name field to something like "Run/Debug Mindustry".
  7. In the Gradle project field, type "Min", then select "Mindustry:desktop".
  8. Set Tasksto run, then click OK.
  9. In the top-right corner, click the green arrow or the bug symbol (there are also shortcuts) in order to run or debug Mindustry.

Running Unit Tests

While there currently are not many unit tests for Mindustry, we encourage you to add some if you have any experience in the field. For example, you could do Test Driven Bugfixing.

  1. Once you successfully compiled Mindustry, create another Run configuration using Run->Edit Configurations.
  2. Select the + icon and select Gradle.
  3. Set the Name field to something like "Test Mindustry".
  4. In the Gradle project field, type "Min", then select "Mindustry:tests".
  5. Set Tasksto test, then click OK.
  6. In the top-right corner, select "Test Mindustry" in the dropdown if it isn't selected, then press the Run or Debug button.
  7. If you want to execute a single test, or a test class, IntelliJ displays clickable green arrows in the test class directly for doing this. Note: Currently, IntelliJ has problems running annotation processors and this option will not work in some cases since generated classes can't be found.
⚠️ **GitHub.com Fallback** ⚠️