Difference between revisions of "Dependencies"

From Forge Community Wiki
(Start page on dependencies)
 
(Add section on hard vs soft dependencies)
Line 1: Line 1:
 
{{Under construction}}
 
{{Under construction}}
A **dependency** is the reliance of a piece of software on another piece of software. In the context of Minecraft Forge, it is a mod or library which another mod has a dependency on.
+
A '''dependency''' is the reliance of a piece of software on another piece of software. In the context of Minecraft Forge, it is a mod or library which another mod has a dependency on.
  
 
Dependencies are declared in three ways:
 
Dependencies are declared in three ways:
* The <code>dependencies</code> block in a Gradle buildscript defines compile-time and runtime dependencies, which is used by the build system and compiler when building or running the mod in the development environment.
+
* The <code>dependencies</code> block in a Gradle buildscript defines compile-time and runtime dependencies, which are used by the build system and compiler when building or running the mod in the development environment.
 
* The act of using classes, fields, and methods from a library creates a dependency on the library in the compiled binaries. The library may be an explicitly declared dependency, or a dependency of an explicitly declared dependency (such as the Guava libraries that Minecraft depends on).
 
* The act of using classes, fields, and methods from a library creates a dependency on the library in the compiled binaries. The library may be an explicitly declared dependency, or a dependency of an explicitly declared dependency (such as the Guava libraries that Minecraft depends on).
 
* [[Proper_Mod_Structuring#Dependency_Configurations|Dependency configurations]] are declared in the <tt>mods.toml</tt> metafile, which is then checked by Forge on runtime on whether they are satisfied.
 
* [[Proper_Mod_Structuring#Dependency_Configurations|Dependency configurations]] are declared in the <tt>mods.toml</tt> metafile, which is then checked by Forge on runtime on whether they are satisfied.
 +
 +
== Hard amd Soft Dependencies ==
 +
There are two types of mod dependencies: hard dependencies, and soft dependencies.
 +
 +
A '''hard dependency''' is a dependency where the dependent mod requires that the dependency is present. This may be in the form of a code dependency, wherein the JVM will crash due to the missing class, field, or method from the dependency, or it may be in the form of a dependency configuration which mandates that the dependency is present.
 +
 +
Hard dependencies should be declared using a dependency configuration to allow the Forge Mod Loader to detect the missing dependency and gracefully handle it by showing an error screen to the user, rather than the JVM crashing with a non-user-friendly exception message.
 +
 +
A '''soft dependency''' is a dependency where the dependent mod does not require the dependency is present, but extra features or compatibility is added in the case of the dependency being present. This often takes the form of cross-mod compatibility features, where a mod soft-depends on another mod or the mod's API.
 +
 +
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.

Revision as of 19:47, 24 March 2021

This page is under construction.

This page is incomplete, and needs more work. Feel free to edit and improve this page!

A dependency is the reliance of a piece of software on another piece of software. In the context of Minecraft Forge, it is a mod or library which another mod has a dependency on.

Dependencies are declared in three ways:

  • The dependencies block in a Gradle buildscript defines compile-time and runtime dependencies, which are used by the build system and compiler when building or running the mod in the development environment.
  • The act of using classes, fields, and methods from a library creates a dependency on the library in the compiled binaries. The library may be an explicitly declared dependency, or a dependency of an explicitly declared dependency (such as the Guava libraries that Minecraft depends on).
  • Dependency configurations are declared in the mods.toml metafile, which is then checked by Forge on runtime on whether they are satisfied.

Hard amd Soft Dependencies

There are two types of mod dependencies: hard dependencies, and soft dependencies.

A hard dependency is a dependency where the dependent mod requires that the dependency is present. This may be in the form of a code dependency, wherein the JVM will crash due to the missing class, field, or method from the dependency, or it may be in the form of a dependency configuration which mandates that the dependency is present.

Hard dependencies should be declared using a dependency configuration to allow the Forge Mod Loader to detect the missing dependency and gracefully handle it by showing an error screen to the user, rather than the JVM crashing with a non-user-friendly exception message.

A soft dependency is a dependency where the dependent mod does not require the dependency is present, but extra features or compatibility is added in the case of the dependency being present. This often takes the form of cross-mod compatibility features, where a mod soft-depends on another mod or the mod's API.

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.