Adding Dependencies allows you to access hooks, tools and apis provided by other mods. Depending on other's code allows you to spend lesser time on writing your code, and more time on refining it. A commonly used dependency in fabric is Fabric API.
Open your build.gradle
file and add the required maven repositories
repositories {
maven {
name = "Example"
url = "https://maven.fabricmc.net"
}
maven{
name = "Tutorial"
url = "https://jitpack.io"
}
[...]
}
The repositories
block must be a top level block. If it does not exist, create it. Do not place the repositories in the repositories
block thats under publishing
To add a dependency, you must know the maven group id, the maven artifact id and the version. These three are the coordinates that will tell gradle to add that dependency. Its also good to know whether the dependency is mod, or not and whether the dependency is an api, or not.
Hard dependencies are usually mods that the core behavior of your mod depends on. They should be included whenever someone adds your mod as a dependency.
Open build.gradle
and under dependencies
, add the following.
[...]
modImplementation "[groupid]:[artifactid]:[version]"
Next, add it to your fabric.mod.json
as so, under depends
"modid":"version"
Soft dependencies are usually mods that your mod adds special behavior to, but are not necessary for main functionaility. These will not be included when your mod is added as a dependency. This can be done by using modCompileOnly
in combination with modRuntime
instead of modImplementation
Open build.gradle
and under dependencies
, add the following.
[...]
modCompileOnly "[groupid]:[artifactid]:[version]"
modRuntime "[groupid]:[artifactid]:[version]"
If the mod is a library, add it to your fabric.mod.json
as so, under suggests
.
"modid":"version"
Sometimes, you need to use a dependency that isn't a mod, like a database connector.
For these, do it the exact same way as adding a mod, but use implementation
, instead of modImplementation
. For soft dependencies of this sort, use compileOnly
and runtime
.
implementation "[groupid]:[artifactid]:[version]"
You should not add these to your fabric.mod.json
as they do not have a mod id and they are not a mod.
Including dependencies within your mod allows you to run your mod as is. The dependency will be stored inside your mod's jar file. To include it, add another line to build.gradle
, under dependencies
.
include "[groupid]:[artifactid]:[version]"