Make sure you have Gradle installed and in your path, so you can run it from command line. Otherwise, you should copy a bootstrapper and the gradle jar into your project.
Use this template build.gradle (for the MC 1.8 unstable branch) for your gradle script:
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 = "0.1.0"
group = "com.mydomain.mymod"
archivesBaseName = "mymod"
minecraft {
*version = "1.8-11.14.0.1274-1.8"*
runDir = "eclipse"
*mappings = "snapshot_nodoc_20141130"*
}
/*
processResources {
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
// substitute values in mcmod.info
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
expand 'version':project.version, 'mcversion':project.minecraft.version
}
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
*/
Save this in a new directory and run gradle setupDecompWorkspace
and gradle build
to set everything up on your local cache. Gradle will be smart and not
have multiple copies of this cache if you are working on multiple mods with
the same target MC version.
Replace version
and mappings
in the minecraft
block to change the MCF
version your mod targets, as well as the obfuscation mappings from MCP to use.
You do not need mappings
if you are using a stable build.
You can uncomment the processResources
block and extend it as necessary to
provide build-time substitution to your mcmod.info
file (which should go in
src/main/resources). A template for mcmod.info
is as follows:
[
{
"modid": "mymod",
"name": "My Mod",
"description": "A mod that does things.",
"version": "${version}",
"mcversion": "${mcversion}",
"url": "http://mydomain.com",
"updateUrl": "",
"authorList": ["Me", "Another person"],
"credits": "Forge, FML, and MCP, for being incredible",
"logoFile": "",
"screenshots": [],
"dependencies": []
}
]
And a hello world template MyModMain.java
for your mod class:
package com.mydomain.mymod;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
@Mod(modid="mymod", name="My Mod", version="0.1.0")
public class MyModMain {
@EventHandler
public void onInit(FMLInitializationEvent event) {
System.out.println("Hello, world!");
}
}
You can generate IDE project files with gradlew idea
for IntelliJ and
gradlew eclipse
for Eclipse.
Useful gradle targets:
runClient
- runs the client using the "eclipse" folder as CWDrunServer
- similar to the above but for the serverbuild
- total build, drops jar inbuild/libs/
clean
- cleans the build directory (doesn't remove IDE project files!)