documentation:fabric_loom
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
documentation:fabric_loom [2019/06/08 13:54] – [Default tasks] jamieswhiteshirt | documentation:fabric_loom [2023/07/05 10:34] – modmuss50 | ||
---|---|---|---|
Line 3: | Line 3: | ||
Fabric Loom, or just Loom for short, is a [[https:// | Fabric Loom, or just Loom for short, is a [[https:// | ||
- | ==== Dependency configurations ==== | + | ==== Useful |
- | + | ||
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | + | ||
- | ==== Default | + | |
- | * '' | ||
- | * '' | ||
* '' | * '' | ||
- | * '' | + | * '' |
- | * '' | + | * '' |
- | * '' | + | |
- | * '' | + | |
* '' | * '' | ||
- | | + | * '' |
- | | + | * '' |
- | * '' | + | * '' |
* '' | * '' | ||
* '' | * '' | ||
* '' | * '' | ||
- | ==== Default configuration | + | ==== Depending on Sub Projects |
- | * Applies the following plugins: '' | + | When setting up a multi-project |
- | * Adds the following Maven repositories: | + | |
- | * Configures the '' | + | |
- | * Configures the '' | + | |
- | * Configures the '' | + | |
- | * If an '' | + | |
- | * Adds '' | + | |
- | * Configures all non-test JavaCompile tasks with configurations for the Mixin annotation processor. | + | |
- | * Configures the '' | + | |
- | * Configures the '' | + | |
- | * Adds the '' | + | |
- | * Configures the '' | + | |
- | * For each MavenPublication (from the '' | + | |
- | * Manually appends dependencies to the POM for mod-augmented dependency configurations, | + | |
- | All run configurations have the run directory '' | + | < |
+ | dependencies | ||
+ | implementation project(path: | ||
+ | } | ||
+ | </code> | ||
- | The client run configuration is configured with '' | + | If you are using splitsource sets in a multi-project build, you will also need to add a dependency |
- | ==== Configuration ==== | + | < |
+ | dependencies { | ||
+ | clientImplementation project(": | ||
+ | } | ||
+ | </ | ||
- | '' | + | ==== Split Client |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | ==== Publishing ==== | + | For years a common source of server crashes has been from mods accidentally calling client only code when installed on a server. The latest loom and loader verions provide an option to require all client code to be moved into its own sourceset. This is done to provide a compile-time guarantee against calling client only Minecraft code or client only API on the server. A single jar file that works on both the client and server is still built from the two sourcesets. |
- | The output of the '' | + | The following snippet from a build.gradle file shows how you can enable this for your mod. As your mod will now be split across two sourcesets, you will need to use the new DSL to define your mods sourcesets. This enables Fabric Loader to group your mods classpath together. This is also useful for some other complex multi-project setups. |
+ | |||
+ | Minecraft 1.18 (1.19 recommended), Loader 0.14 and Loom 1.0 or later are required | ||
- | When using the '' | ||
< | < | ||
- | mavenJava(MavenPublication) | + | loom { |
- | | + | splitEnvironmentSourceSets() |
- | | + | |
- | } | + | mods { |
- | // artifact(sourcesJar) | + | |
- | // | + | |
- | // | + | |
- | ... | + | } |
- | } | + | } |
+ | } | ||
</ | </ | ||
- | When publishing | + | ==== Multi project Optimisation ==== |
+ | |||
+ | If your Gradle project has many subprojects that use the same Minecraft version such as Fabric-API, starting with Loom 1.1 you can now opt-in to advanced optimistations. Adding < | ||
+ | |||
+ | ==== Options ==== | ||
+ | |||
+ | < | ||
+ | loom { | ||
+ | // Set the access widener path, see https:// | ||
+ | accessWidenerPath = file(" | ||
+ | |||
+ | // Add additional log4j config files. | ||
+ | log4jConfigs.from(file(" | ||
+ | |||
+ | // When enabled the output archives will be automatically remapped. | ||
+ | remapArchives = true | ||
+ | // When enabled the -dev jars in the *Elements configurations will be replaced by the remapped jars | ||
+ | setupRemappedVariants = true | ||
+ | // When enabled transitive access wideners will be applied from dependencies. | ||
+ | enableTransitiveAccessWideners = true | ||
+ | // When enabled log4j will only be on the runtime classpath, forcing the use of SLF4j. | ||
+ | runtimeOnlyLog4j = false | ||
+ | |||
+ | // When set only server related features and jars will be setup. | ||
+ | serverOnlyMinecraftJar() | ||
+ | // When set the minecraft jar will be split into common and clientonly. Highly experimental, | ||
+ | splitMinecraftJar() | ||
+ | |||
+ | // Used to configure existing or new run configurations | ||
+ | runs { | ||
+ | client { | ||
+ | // Add a VM arg | ||
+ | vmArgs " | ||
+ | // Add a JVM property | ||
+ | property(" | ||
+ | // Add a program arg | ||
+ | programArg " | ||
+ | // Add an environment variable | ||
+ | environmentVariable(" | ||
+ | // The environment (or side) to run, usually client or server. | ||
+ | environment = " | ||
+ | // The full name of the run configuration, | ||
+ | configName = " | ||
+ | // The default main class of the run configuration. This will be overridden if using a mod loader with a fabric_installer.json file. | ||
+ | defaultMainClass = "" | ||
+ | // The run directory for this configuration, | ||
+ | runDir = " | ||
+ | // The sourceset to run, commonly set to sourceSets.test | ||
+ | source = sourceSets.main | ||
+ | // When true a run configuration file will be generated | ||
+ | ideConfigGenerated = true | ||
+ | |||
+ | // Configure run config with the default client options. | ||
+ | client() | ||
+ | |||
+ | // Configure run config with the default server options. | ||
+ | server() | ||
+ | } | ||
+ | |||
+ | // Example of creating a basic run config for tests | ||
+ | testClient { | ||
+ | // Copies settings from another run configuration. | ||
+ | inherit client | ||
+ | |||
+ | configName = "Test Minecraft Client" | ||
+ | source = sourceSets.test | ||
+ | } | ||
+ | |||
+ | // Example of removing the built-in server configuration | ||
+ | remove server | ||
+ | } | ||
+ | |||
+ | // Configure all run configs to generate ide run configurations. Useful for sub projects. | ||
+ | runConfigs.configureEach { | ||
+ | ideConfigGenerated = true | ||
+ | } | ||
+ | |||
+ | // Used to configure mixin options or apply to additional source sets. | ||
+ | mixin { | ||
+ | // When disabled tiny remapper will be used to remap Mixins instead of the AP. Experimental. | ||
+ | useLegacyMixinAp = true | ||
+ | // Set the default refmap name | ||
+ | defaultRefmapName = " | ||
+ | |||
+ | // See https:// | ||
+ | } | ||
+ | |||
+ | // Configure or add new decompilers | ||
+ | decompilers { | ||
+ | // Configure a default decompiler, either cfr or fernflower | ||
+ | cfr { | ||
+ | // Pass additional options to the decompiler | ||
+ | options += [ | ||
+ | key: " | ||
+ | ] | ||
+ | // Set the amount of memory in meagabytes used when forking the JVM | ||
+ | memory = 4096 | ||
+ | // Set the maximum number of threads that the decompiler can use. | ||
+ | maxThreads = 8 | ||
+ | } | ||
+ | } | ||
+ | |||
+ | interfaceInjection { | ||
+ | // When enabled injected interfaces from dependecies will be applied. | ||
+ | enableDependencyInterfaceInjection = true | ||
+ | } | ||
+ | |||
+ | // Splits the Minecraft jar and incoming dependencies across the main (common) and client only sourcesets. | ||
+ | // This provides compile time safety for accessing client only code. | ||
+ | splitEnvironmentSourceSets() | ||
+ | |||
+ | // This mods block is used group mods that are made up of multiplue classpath entries. | ||
+ | mods { | ||
+ | modid { | ||
+ | // When using split sources you should add the main and client sourceset | ||
+ | sourceSet sourceSets.main | ||
+ | sourceSet sourceSets.client | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // Create modExampleImplementation and related configurations that remap mods. | ||
+ | createRemapConfigurations(sourceSets.example) | ||
+ | } | ||
+ | |||
+ | remapJar { | ||
+ | // Set the input jar for the task, also valid for remapSourcesJar | ||
+ | inputFile = file(" | ||
+ | // Set the source namespace, also valid for remapSourcesJar | ||
+ | sourceNamespace = " | ||
+ | // Set the target namespace, also valid for remapSourcesJar | ||
+ | targetNamespace = " | ||
+ | // Add additional jar files to the remap classpath, also valid for remapSourcesJar | ||
+ | classpath.from file(" | ||
+ | |||
+ | // Add a nested | ||
+ | nestedJars.from file(" | ||
+ | // When enabled nested jars will be included with the output jar. | ||
+ | addNestedDependencies = true | ||
+ | } | ||
+ | |||
+ | dependencies | ||
+ | // Set the minecraft version. | ||
+ | minecraft " | ||
+ | |||
+ | // Use mappings from maven. | ||
+ | mappings " | ||
+ | |||
+ | // Use the offical mojang mappings | ||
+ | mappings loom.officialMojangMappings() | ||
+ | |||
+ | // Layered mappings using official mojang mappings and parchment. | ||
+ | mappings loom.layered() { | ||
+ | officialMojangMappings() | ||
+ | // Use parchment mappings. NOTE: Parchment maven must be manually | ||
+ | parchment(" | ||
+ | } | ||
+ | |||
+ | // Remap a mod from maven and apply to gradle' | ||
+ | // (Minor detail: it's not exactly applied *to* the configuration, | ||
+ | modImplementation " | ||
+ | |||
+ | // Remap a mod from maven and apply to gradle' | ||
+ | modApi "net.fabricmc.fabric-api: | ||
+ | |||
+ | // Remap a mod from maven and apply to gradle' | ||
+ | modCompileOnly " | ||
+ | |||
+ | // Remap a mod from maven and apply to gradle' | ||
+ | modCompileOnlyApi " | ||
+ | |||
+ | // Remap a mod from maven and apply to gradle' | ||
+ | modRuntimeOnly " | ||
+ | |||
+ | // Remap a mod from maven and apply to loom's localRuntime configuration. | ||
+ | // Behaves like runtimeOnly but is not exposed in to dependents. A bit like testRuntimeOnly but for mods. | ||
+ | modLocalRuntime " | ||
+ | |||
+ | // Include a mod jar in the remapped jar. None transitive. | ||
+ | include " | ||
+ | |||
+ | // Include a none mod library jar in the remapped jar. A dummy mod will be generated. None transitive. | ||
+ | include " | ||
+ | |||
+ | // Helper | ||
+ | modImplementation fabricApi.module(" | ||
+ | |||
+ | // Depend on a loom sub project by using the namedElements configuration. | ||
+ | implementation project(path: | ||
+ | } | ||
+ | </ | ||
- | ==== Useful task types ==== | + | ==== Resolving issues |
- | * '' | + | Loom and/or gradle can sometimes fail due to corrupted cache files. Running |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
==== Development environment setup ==== | ==== Development environment setup ==== | ||
Line 96: | Line 258: | ||
- Downloads the configured mappings. | - Downloads the configured mappings. | ||
- Remaps the merged jar with intermediary mappings to produce an intermediary jar. | - Remaps the merged jar with intermediary mappings to produce an intermediary jar. | ||
- | - Remaps the intermediary | + | - Remaps the merged |
- Optional: Decompiles the mapped jar to produce a mapped sources jar and linemap, and applies the linemap to the mapped jar. | - Optional: Decompiles the mapped jar to produce a mapped sources jar and linemap, and applies the linemap to the mapped jar. | ||
- Adds dependencies of Minecraft. | - Adds dependencies of Minecraft. | ||
Line 108: | Line 270: | ||
* '' | * '' | ||
* '' | * '' | ||
+ | |||
+ | ==== Dependency configurations ==== | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | ==== Default configuration ==== | ||
+ | |||
+ | * Applies the following plugins: '' | ||
+ | * Adds the following Maven repositories: | ||
+ | * Configures the '' | ||
+ | * Configures the '' | ||
+ | * Configures the '' | ||
+ | * If an '' | ||
+ | * Adds '' | ||
+ | * Configures all non-test JavaCompile tasks with configurations for the Mixin annotation processor. | ||
+ | * Configures the '' | ||
+ | * Configures the '' | ||
+ | * Adds the '' | ||
+ | * Configures the '' | ||
+ | * For each MavenPublication (from the '' | ||
+ | * Manually appends dependencies to the POM for mod-augmented dependency configurations, | ||
+ | |||
+ | All run configurations have the run directory '' | ||
+ | |||
+ | The client run configuration is configured with '' | ||
+ | |||
+ |
documentation/fabric_loom.txt · Last modified: 2023/12/22 14:39 by modmuss50