Changes

1,896 bytes added ,  12:57, 2 April 2021
add WIP section on declaring dependencies
Line 17: Line 17:     
Soft dependencies usually take the form of isolated code dependencies, where the code that depends on the soft-dependency is isolated from the rest of the mod until the soft-dependency is detected as being present.
 
Soft dependencies usually take the form of isolated code dependencies, where the code that depends on the soft-dependency is isolated from the rest of the mod until the soft-dependency is detected as being present.
 +
 +
== Declaring Dependencies ==
 +
A mod declares a dependency on a mod or library through Gradle, through the <code>dependencies</code> block.<ref>[https://docs.gradle.org/6.8.1/userguide/declaring_dependencies.html Gradle User Guide for 6.8.1: ''Declaring dependencies'']</ref>
 +
 +
For example, to declare a dependency on the <code>net:minecraftforge:eventbus:4.0.0</code> library from the <code>main</code> source set:
 +
<syntaxhighlight lang="gradle">
 +
dependencies {
 +
    // 'implementation' is for the main source set
 +
    implementation "net:minecraftforge:eventbus:4.0.0"
 +
}
 +
</syntaxhighlight>
 +
 +
{{Tip|ForgeGradle automatically adds the [https://files.minecraftforge.net/maven/ Forge Maven] and [https://maven.apache.org/repository/ Maven Central] repositories to projects. If a dependency is not present in these (such as dependencies on other mods), the repository containing the dependency must be declared in the <code>repositories</code> block of the Gradle buildscript.<ref>[hhttps://docs.gradle.org/6.8.1/userguide/declaring_repositories.html Gradle User Guide for 6.8.1: ''Declaring repositories'']</ref>}}
 +
 +
=== Deobfuscating Dependencies ===
 +
Mods (and libraries which use Minecraft code) are usually released as an SRG-obfuscated JAR, which prevents their direct use in development environments due to mismatch between SRG names from the mod/library and the MCP/mapped names in the development environment.
 +
 +
These mods/libraries must be deobfuscated to the development environment's mappings first. This is done using the <code>fg.deobf</code> function, which creates a dependency which is dynamically remapped to the local environment's mappings.
 +
 +
For example, to declare a dependency on the <code>mezz.jei:jei-1.16.5:7.6.1.75</code> library (which is obfuscated):
 +
<syntaxhighlight lang="gradle">
 +
dependencies {
 +
    implementation fg.deobf("mezz.jei:jei-1.16.5:7.6.1.75")
 +
}
 +
</syntaxhighlight>
297

edits