Basic Modding - Release your Mod

Goal

I want to show you how to compile your Mod to a .jar file which can be shared. 

Difficulty

1/10 - Pretty Simple

Prerequisites

  • You need to be able to change the environment variables of your computer
  • You need to have a mod to release

Forge Version

This should work for every Forge Version. It only can differ with other gradle versions, but this is very unlikely.


Installing Gradle

To compile your Mod you first need to install Gradle on your Computer. To do this, go to Gradle's Download Page and download the latest stable full ("all") version. This will be a .zip File. Extract it to a folder you want. I extracted it to C:\Gradle\.

Then you have to edit your Environment variables: You need to find the "Path" Variable and add the following path to it: C:\Gradle\gradle-*.**\bin. Replace the stars with the version of Gradle. You can use the Explorer to check which exact path you need to use.

Now open a command prompt and type "gradle". If you get some output after a bit of time, everything is right.


If you don't want to install gradle, you can call the gradlew file in the forge directory instead. However, you need to run it from your mod's directory, otherwise you'll be building the Forge example mod.

build.gradle

The next thing we need is the so called "buildfile". This is a file named build.gradle which contains information on the build process, for example the files which need to be compiled. You can find a buildfile in the directory where you installed Minecraft Forge. You can use this one and copy it into your workspace or you create a new file and paste this content:

build.gradle:
buildscript {
    repositories {
        mavenCentral()
        maven {
            name = "forge"
            url = "http://files.minecraftforge.net/maven"
        }
        maven {
            name = "sonatype"
            url = "https://oss.sonatype.org/content/repositories/snapshots/"
        }
    }
    dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
    }
}

apply plugin: 'forge'

version = "version"
group= "com.yourname.modid" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "Modname"

sourceSets {
    main {
        java { srcDirs = ["$projectDir/src/java"] }
        resources { srcDirs = ["$projectDir/src/resources"] }
    }
}

minecraft {
    version = "1.7.10-10.13.0.1180"
    runDir = "eclipse/assets"
}

processResources
{
    // this will ensure that this task is redone when the versions change.
    inputs.property "version", project.version
    inputs.property "mcversion", project.minecraft.version

    // replace stuff in mcmod.info, nothing else
    from(sourceSets.main.resources.srcDirs) {
        include 'mcmod.info'
                
        // replace version and mcversion
        expand 'version':project.version, 'mcversion':project.minecraft.version
    }
        
    // copy everything else, thats not the mcmod.info
    from(sourceSets.main.resources.srcDirs) {
        exclude 'mcmod.info'
    }
}


There are several lines which are important. First we take a look at these lines:

build.gradle:
sourceSets {
    main {
        java { srcDirs = ["$projectDir/src/java"] }
        resources { srcDirs = ["$projectDir/src/resources"] }
    }
}

These lines define where gradle looks for code and resources. Files in the code directory which end with .java are compiled and put into the generated .jar file. Files in the resources directory are simply copied.

Like I said in earlier Tutorials, it's useful do seperate the code from the resources. Here, the code is placed in project/src/java and the resources in project/src/resources. "Project" is the folder of the eclipse project which contains the sourcecode. In this folder you need to place the buildfile.

 

The next important lines are these ones:

build.gradle:
version = "version"
group= "com.yourname.modid" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "Modname"

Here you need to replace "version" with the version of your Mod (The same String you used in your main class for the @Mod annotation). To make the version better readable you can add the minecraft version in front of it or behind it: "v.1.0.0-mc1.7.10". The exact version is not important, it is just appended to the name.

Group is a group ID for the mod, this should be something like com.yourname.modid, which should be the same as the path to your main class.

ArchivesBaseName is the name of the generated .jar file. This should be your Modname.

 

This is how these lines can look like:

build.gradle:
version = "v.1.3.1-mc1.7.10"
group= "com.bedrockminer.weaponcraft" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "WeaponCraft"


Another important part is the version of Forge:

build.gradle:
minecraft {
    version = "1.7.10-10.13.0.1180"
    runDir = "eclipse/assets"
}

The "version" here must be the exact same value as the version number of you currently installed version of Forge. If you are unsure which version number to use, take a look at the build.gradle file in your Forge directory, search for these lines and copy the version.


The last thing we have to look for are these lines:

build.gradle:
dependencies {
    classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
}

These lines define the version of Gradle. Depending on your Forge version you have to use different versions of Gradle. This value can also be copied from the build.gradle file in the Forge directory. It will get important if we update Forge because then it might need to be changed.


The other lines in the buildfile are not that important because they never change. Just ensure that the lines I mentioned are correctly set for your mod, then it will work.

Compiling the Mod

Now we finally start compiling your Mod. To do this, open the command prompt in the directory where you placed the buildfile. Then type gradle build (or path/to/gradlew build if you didn't install gradle). This will start the build procedure of the Mod. It can take some minutes for gradle to grab the required libraries and files, so be patient, the second build will be much faster.

 

Unfortunately, there can be errors, even if there were none in eclipse. Gradle outputs them before terminating the compiling process. If you get some errors, you need to fix them, otherwise your mod cannot be built. Most of the errors are caused by different Java versions: Minecraft uses Java 1.6, if you're using a higher version, some features or methods you used may be not available. Then you'll need to find an alternative.

If you can't find working alternatives by any means or if you don't understand certain errors, please contact me.

 

When the build has finished successfully, you can go to project/build/libs. There you will find the compiled file. It's name will be: archivesBaseName-version.jar.

This file is a fully compiled Mod and can be placed in the mods folder of your Minecraft Client.

By the way, always (!!!)  test your mods in the client before you upload them because there can be some bugs with Compiling because of the obfuscator or different Java versions that are not shown by gradle.


Recommended tutorials to continue with

Take a look at the tutorial overview and find out what you want to do next!


Comments and Questions:

If you want to report modding problems, please make sure to include the code in a pastebin link or something else! Don't just write "It doesn't work", otherwise your post will be deleted. For more complicated problems, please use the troubleshooter form.