There are no tutorials for this at all whatsoever. If you have no experience with gradle, then you're gonna be very lost. Considering that the docs only cover the basics, I couldn't navigate my way through the docs. I've had some help with a couple of friends, primarily UpcraftLP as well as just seeing how gradle scripts are structured in other mods, and some googling around and the use of stackoverflow really helped me out greatly. Here are some things you need to know before you start getting into this tutorial:
Who This Is For:
This is for anybody that is looking to add libraries and mods to their dependencies.
What This Is For:
This is for primarily to learn how to set up dependencies.
What Do I Need To Start:
You need (recommended) IntelliJ installed. If you are content with Eclipse, then please know that IntelliJ comes with up-to-date plugins necessary for development with Minecraft Forge modding include but not limited to:
Gradle Maven Ant Version Control Modules Test Units Decompiler Terminal and more
However, IntelliJ is not required but recommended to follow along accurately. Unless you have a Gradle plugin installed into your Eclipse, then it will be difficult for you to do so.
Now, let's begin.
This is gonna be a bit lengthy but just incase you're looking for specific parts of the tutorial, all the different parts of the tutorial will be in spoilers for easy navigation.
What is Gradle?
Gradle is a build scripting framework that allows you to effectively and efficiently run a script with certain commands called "Tasks" that allow you to set up and even distribute your project in some way. This is useful for projects that run specifically on a certain API. An example of this is the Minecraft Forge API. The API is required to make an effective and cross-mod-compatible mod that works on both client and server. The Forge gods decided to use Gradle due to the fact that it can download other libraries from either github or maven repositories (and others as well) and includes them into your project's external libraries. This way you don't have to configure everything yourself and spend like half an hour trying to get things to work. Another thing that Gradle allows you to do is to set up a project necessary for developing applications (or mods in this case) that run off of the API in question (Forge in this case). The API developers that are enabling Gradle have to write some Groovy scripts in order to tell Gradle exactly what to do with the setup. In this case, Forge is decompiling the Minecraft runnable jar into viewable code alongside the Forge Source jar, which are both bundled together. It is also retrieving all the necessary dependencies needed to run Minecraft and Forge (such as guava, gson, LWJGL, OpenAL, some Mojang libs for authentication and realms related functionality, etc. This way, anybody that is needing to set up a Forge mod project can just run a few tasks (or commands) to set up and they'll be good to go. Before setting up, some would want to add some dependencies (like Just Enough Items) before actually starting their project. Sometimes, even after you set up your project, you decide that there is a library/mod that you need, so you add the dependency to your Gradle script, update your Gradle project, and you're good to go. Gradle is a powerful tool, but maybe it has too much power?
What are dependencies?
There are two different kinds of dependencies with Forge: soft dependencies and hard dependencies. Soft dependencies are dependencies that really are not required at all, but if you do have it installed into your client along with the mod in question, then there can be some extra stuff added to it, but again, not required. A hard dependency is just as it sounds, after reading what a soft dependency is. It's literally the opposite. It's a dependency that is required to run the mod in question. I'll show you some examples of the use in an actual project in the future, but for now, we gotta stick to the basics.
How do I add a soft dependency?
To add in a soft dependency, you will need to use the Forge Mod Loader plugin. We will showcase the Baubles mod.
@Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION) public class ExampleMod { public static final String MODID = "examplemod"; public static final String VERSION = "1.0";
@EventHandler public void init(FMLInitializationEvent event) { System.out.println("Baubles is installed: " + Loader.isModLoaded("baubles")); //This here checks if the soft dependency is loaded. } }
This checks to see if the Baubles mod is loaded into forge. Forge will load all the mods in the mods folder first before starting them up. So using this member function is crucial if you want a soft dependency.
How do I use a hard dependency?
I'll show just the inclusion of a hard dependency. A hard dependency is specified by your main mod class that the mod should not be loaded up unless the specified mod is also loaded.
To add in a hard dependency, you're gonna need to go into your main mod class, and at the top of your class, you need to do something along the lines of this (I am going to be showing the inclusion of Baubles again):
@Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION, dependencies = "required-after:baubles")
public class ExampleMod
{
public static final String MODID = "examplemod";
public static final String VERSION = "1.0";
@EventHandler
public void init(FMLInitializationEvent event)
{
System.out.println("Baubles is installed: " + Loader.isModLoaded("baubles"));
}
}
If you do not have Baubles included in your libraries, then forge will not continue to load your mod, and you will be presented with a screen just like this:
Now the thing about adding in hard dependencies like this is you have make sure that you're doing it right. I literally spent like since last night trying to figure out why this wasn't working, mainly because I don't ever use hard dependencies. I only do gradle dependencies.
Now I know how to specify a dependency during forge load up, how do I actually get the dependency into my project so that I can do stuff with it?
There are actually two main different ways of doing this. you can either have gradle handle the dependency, or you can include it in a folder in your project root. Forge looks for a folder called "libs". If you create that folder and place your dependency jars in there, then forge will load them up for you. However, in order to actually work with a hard dependency, you have to include the mod in your root folder's run/mods folder, otherwise, you'll get the error screen as displayed in the last section.
There is also a way to get a dependency remotely. We will use Just Enough Items. There are different ways to specify how gradle includes the dependency in your project. You can either compile it or include it at runtime. When you compile it, then you get access to its source code just like you would with the Forge API, or Gson, or Guava, and even the standard library (which should always be included in your project, otherwise I have no idea how you're even making mods). When you include it at runtime, then it just downloads the library and uses it for runtime use only, which is when it is used during the start and running of the actual project.
The first script we will use is a runtime dependency script for Just Enough Items (or jei).
runtime "mezz.jei:jei_1.11.2:4.5.0.294"
As you can see, we specify the word "runtime" so that gradle knows that it should only be used at runtime. However, a lot of times, you won't be able to just get the dependency on demand. You have to make sure there is a repo for it. The most common ways to do so is to find a maven repo for the dependency. So we need to go into our "repositories" block, or make one if you don't have it, and tell gradle to look for a certain maven repo host.
If you run your project now with everything we've done up to now, you should get 7 mods installed, and both baubles and jei should be in your Mods GUI in the main menu. Now if you wanna use jei to add stuff to it like your items and blocks and whatnot, then you need to compile the api. The script looks a bit like this:
compile "mezz.jei:jei_1.11.2:4.5.0.294:api"
Now you just need to refresh your gradle project and look into your external libraries and it should be in there, and you're good to go.
That is all I am doing for now. If you want more, which I can do more, then let me know. If you have any tips or if you wanna add stuff to this, then please do so in the comments. If I've missed something or explained something wrong then please let me know.
There are no tutorials for this at all whatsoever. If you have no experience with gradle, then you're gonna be very lost. Considering that the docs only cover the basics, I couldn't navigate my way through the docs. I've had some help with a couple of friends, primarily UpcraftLP as well as just seeing how gradle scripts are structured in other mods, and some googling around and the use of stackoverflow really helped me out greatly. Here are some things you need to know before you start getting into this tutorial:
Who This Is For:
What This Is For:
What Do I Need To Start:
Now, let's begin.
This is gonna be a bit lengthy but just incase you're looking for specific parts of the tutorial, all the different parts of the tutorial will be in spoilers for easy navigation.
What is Gradle?
Gradle is a build scripting framework that allows you to effectively and efficiently run a script with certain commands called "Tasks" that allow you to set up and even distribute your project in some way. This is useful for projects that run specifically on a certain API. An example of this is the Minecraft Forge API. The API is required to make an effective and cross-mod-compatible mod that works on both client and server. The Forge gods decided to use Gradle due to the fact that it can download other libraries from either github or maven repositories (and others as well) and includes them into your project's external libraries. This way you don't have to configure everything yourself and spend like half an hour trying to get things to work. Another thing that Gradle allows you to do is to set up a project necessary for developing applications (or mods in this case) that run off of the API in question (Forge in this case). The API developers that are enabling Gradle have to write some Groovy scripts in order to tell Gradle exactly what to do with the setup. In this case, Forge is decompiling the Minecraft runnable jar into viewable code alongside the Forge Source jar, which are both bundled together. It is also retrieving all the necessary dependencies needed to run Minecraft and Forge (such as guava, gson, LWJGL, OpenAL, some Mojang libs for authentication and realms related functionality, etc. This way, anybody that is needing to set up a Forge mod project can just run a few tasks (or commands) to set up and they'll be good to go. Before setting up, some would want to add some dependencies (like Just Enough Items) before actually starting their project. Sometimes, even after you set up your project, you decide that there is a library/mod that you need, so you add the dependency to your Gradle script, update your Gradle project, and you're good to go. Gradle is a powerful tool, but maybe it has too much power?
What are dependencies?
There are two different kinds of dependencies with Forge: soft dependencies and hard dependencies. Soft dependencies are dependencies that really are not required at all, but if you do have it installed into your client along with the mod in question, then there can be some extra stuff added to it, but again, not required. A hard dependency is just as it sounds, after reading what a soft dependency is. It's literally the opposite. It's a dependency that is required to run the mod in question. I'll show you some examples of the use in an actual project in the future, but for now, we gotta stick to the basics.
How do I add a soft dependency?
To add in a soft dependency, you will need to use the Forge Mod Loader plugin. We will showcase the Baubles mod.
This checks to see if the Baubles mod is loaded into forge. Forge will load all the mods in the mods folder first before starting them up. So using this member function is crucial if you want a soft dependency.
How do I use a hard dependency?
I'll show just the inclusion of a hard dependency. A hard dependency is specified by your main mod class that the mod should not be loaded up unless the specified mod is also loaded.
To add in a hard dependency, you're gonna need to go into your main mod class, and at the top of your class, you need to do something along the lines of this (I am going to be showing the inclusion of Baubles again):
If you do not have Baubles included in your libraries, then forge will not continue to load your mod, and you will be presented with a screen just like this:
Now the thing about adding in hard dependencies like this is you have make sure that you're doing it right. I literally spent like since last night trying to figure out why this wasn't working, mainly because I don't ever use hard dependencies. I only do gradle dependencies.
Now I know how to specify a dependency during forge load up, how do I actually get the dependency into my project so that I can do stuff with it?
There are actually two main different ways of doing this. you can either have gradle handle the dependency, or you can include it in a folder in your project root. Forge looks for a folder called "libs". If you create that folder and place your dependency jars in there, then forge will load them up for you. However, in order to actually work with a hard dependency, you have to include the mod in your root folder's run/mods folder, otherwise, you'll get the error screen as displayed in the last section.
There is also a way to get a dependency remotely. We will use Just Enough Items. There are different ways to specify how gradle includes the dependency in your project. You can either compile it or include it at runtime. When you compile it, then you get access to its source code just like you would with the Forge API, or Gson, or Guava, and even the standard library (which should always be included in your project, otherwise I have no idea how you're even making mods). When you include it at runtime, then it just downloads the library and uses it for runtime use only, which is when it is used during the start and running of the actual project.
The first script we will use is a runtime dependency script for Just Enough Items (or jei).
As you can see, we specify the word "runtime" so that gradle knows that it should only be used at runtime. However, a lot of times, you won't be able to just get the dependency on demand. You have to make sure there is a repo for it. The most common ways to do so is to find a maven repo for the dependency. So we need to go into our "repositories" block, or make one if you don't have it, and tell gradle to look for a certain maven repo host.
If you run your project now with everything we've done up to now, you should get 7 mods installed, and both baubles and jei should be in your Mods GUI in the main menu. Now if you wanna use jei to add stuff to it like your items and blocks and whatnot, then you need to compile the api. The script looks a bit like this:
Now you just need to refresh your gradle project and look into your external libraries and it should be in there, and you're good to go.
That is all I am doing for now. If you want more, which I can do more, then let me know. If you have any tips or if you wanna add stuff to this, then please do so in the comments. If I've missed something or explained something wrong then please let me know.
If you would like to get a hold of me somehow, then my discord is @Alex Couch#5275.
ty, this helped a ton