This post is meant to help those not accustomed to building with Gradle, but wanting to use separate directories for making mods. (I think some people name it "Pahimar setup" or something...)
As each setup can be different, I will take mine as a reference (the "Goto setup" ), and explain it as simply as possible.
Before beginning
This tutorial is meant to be IDE independent, and as such, use "conventional" naming of things and doesn't describe IDE settings step. Those you should know how to do, since you are supposed to choose your IDE while learning to code.
For example, a "Project" is a group of resources, eventually with dependencies, that can be run. Eclipse uses this term, while IntellijIdea uses "Module". Not to be confused with IntellijIdea "Project" (which can be a group of projects) nor Gradle "Project", which are things that can be "built" through Gradle.
I personally go with one "Project" = one mod = one Gradle "Project". (because Forge recommended it this way, and it makes sense too)
The "dependency" setup
This setup is based on dependencies, so build files are simplified and easier to change.
My directories are as follows:
-Forge (the folder inside which forge source has been extracted, per the main tutorial)
\build.gradle
\settings.gradle
-Project1 (another folder, which contains the mod1)
\build.gradle
-Project2 (another folder, which contains the mod2)
etc.
Note the new file, settings.gradle, which only contain:
includeFlat 'Project1','Project2'
This basically specify that "Project1" and "Project2" folders depend on the Forge folder. For example you code a main core API in the Forge source, and dependent mods in the other folders. You can add more to the list.
Specific subfolders can be added with line such as 'Project/subfolder'.
You can make it a bit more intelligent with code for folder look-up, but this is outside of my post scope.
build.gradle in Forge folder is a modified version of the file shipped with Forge sources:
[spoiler=For 1.6.4]
buildscript {
repositories {
mavenCentral()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:1.0-SNAPSHOT'
}
}
allprojects {
apply plugin: 'forge'
minecraft{version = "1.6.4-9.11.1.964"}
version = "1.0"
archivesBaseName = project.projectDir.name
}
[spoiler=For 1.7.2]
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.1-SNAPSHOT'
}
}
allprojects {
apply plugin: 'forge'
minecraft{version = "1.7.2-10.12.0.985"}
version = "1.0"
archivesBaseName = project.projectDir.name
}
It adds a body to "allprojects" with basic settings, such as applying forge, settings minecraft version and a general name for the mod jar. (
archivesBaseName
) This body applies parameters to all projects, including the Forge one.
Use "subprojects" to work on all projects except the Forge one.
Let see how it simplify the mod build.gradle, for example the Project1/build.gradle:
version = "1.1"
sourceSets.main{
java{
srcDirs project.projectDir.getPath() exclude ("bin/**", "build*")
}
resources{
srcDirs project.projectDir.getPath() exclude ("bin/**", "build*")
}
}
processResources {
// 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'
}
}
The first body is made to set the mod source differently. With this, the "Project1" folder contains directly the source package, without "src/main/" intermediate folders, and making sure all superfluous files are excluded (here, a "bin" folder, and any file or folder whose name begin with "build").
Project1
\assets\modid1\textures\...
\mods\modid1\...
Of course, this entire file is optional and highly dependent on your own setup.
Note that
project.projectDir
reference the folder as File, for easy copy-pasting in another mod folder.
Now we can test the build with
gradlew build
by command line in Forge folder.
Or with the Gradle plugin in Eclipse, open the gradle view and launch the "build" task for the Forge imported Gradle project.
You should now have a simple jar into each Project/build/libs
The "Independent" setup
Again, you have multiple mods in separate folders, but don't want to use the Forge folder, nor do you want to build all mods at the same time.
Indeed, you don't need to.
Per the main tutorial, you made a Forge project, ran with either
gradlew setupDevWorkspace
or
gradlew setupDecompWorkspace
ForgeGradle and its dependencies should now be cached.
Copy over the build.gradle file from the Forge folder in all your mods roots. (plus the gradle folder and gradlew files if you don't want to install Gradle)
You can now delete the Forge project folder.
With this project structure:
Project2
\resources\assets\modid\textures\...
\src\mods\modid\...
\build.gradle
A valid build.gradle file is:
[spoiler=For 1.6.4]
buildscript {
repositories {
mavenCentral()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:1.0-SNAPSHOT'
}
}
apply plugin: 'forge'
minecraft{version = "1.6.4-9.11.1.964"}
version = "1.0"//Set the mod version, is appended to the end of the jar name
archivesBaseName = project.projectDir.name// Set the jar name as the project root folder name
//Optional: change the project structure
sourceSets.main{
java{
srcDirs 'src'//set the source folder as the /src subfolder
}
resources{
srcDirs 'resources'//set the resources folder as the /resources subfolder
}
}
processResources {
// 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'
}
}
[spoiler=For 1.7.2]
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.1-SNAPSHOT'
}
}
apply plugin: 'forge'
minecraft{version = "1.7.2-10.12.0.985"}
version = "1.0"//Set the mod version, is appended to the end of the jar name
archivesBaseName = project.projectDir.name// Set the jar name as the project root folder name
//Optional: change the project structure
sourceSets.main{
java{
srcDirs 'src'//set the source folder as the /src subfolder
}
resources{
srcDirs 'resources'//set the resources folder as the /resources subfolder
}
}
processResources {
// 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'
}
}
You can now import the mod project in your favourite IDE , with the build.gradle file.
You can also run
gradlew build
by command line in a project folder, to get the corresponding mod jar in its build/libs subfolder.