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.
You need to have the following things installed (they are pretty standard for open source Java projects):
- [Java SE Development Kit (JDK) 8:] (https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
- [Git] (https://git-scm.com/downloads)
- [IntelliJ IDEA] (https://www.jetbrains.com/idea/download/) (If you want to use Eclipse instead, feel free, but you may need to do additional work.)
Additionally, a GitHub account is highly recommended. This guide will assume you have one.
- After logging in to GitHub, go to https://github.com/Anuken/Mindustry and click the "Fork" button in the top-right corner.
- Click on "Clone or download" and copy the link
- 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).
- 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".
- Wait for like 5 minutes. Unfortunately, you currently don't seem to get any progress in the GUI.
- Close the Git GUI.
In order to properly work with the repository in future, there are a couple of things to do.
- 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) - 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 - Type
git remote -vagain and check the output. You will see that git now knows about bothoriginandupstream. - To test it, we can try pulling from the original repository:
git pull upstream master
This means we will pull themasterbranch of theupstreamrepository into the currently checked out branch (which ismastersince 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 anAlready up to date.message or some command line spam. - Our local
cloneof theoriginrepository now contains the most recent changes of theupstreamrepository, butorigin(your fork on Github) does not contain these changes (if any). In order to get them there, you need to dogit push origin master
This basically means you push your current branch into themasterbranch of theoriginrepository. If there were no changes, you'll get anEverything up-to-datemessage, but at least now you know how stuff works. - 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.
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).
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
- Open IntelliJ IDEA. In the welcome screen, select
Import Project. - Navigate to your Mindustry
cloneand select thebuild.gradlefile in the root directory, then press OK. - Check
auto-importand press OK again. Gradle will start loading stuff in background. This may take a while when done the first time. - In IntelliJ IDEA, select
Run->Edit Configurations. - Select the
+icon and selectGradle. - Set the
Namefield to something like "Run/Debug Mindustry". - In the
Gradle projectfield, type "Min", then select "Mindustry:desktop". - Set
Taskstorun, then click OK. - In the top-right corner, click the green arrow or the bug symbol (there are also shortcuts) in order to run or debug Mindustry.
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.
- Once you successfully compiled Mindustry, create another Run configuration using
Run->Edit Configurations. - Select the
+icon and selectGradle. - Set the
Namefield to something like "Test Mindustry". - In the
Gradle projectfield, type "Min", then select "Mindustry:tests". - Set
Taskstotest, then click OK. - In the top-right corner, select "Test Mindustry" in the dropdown if it isn't selected, then press the Run or Debug button.
- 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.