User Tools

Site Tools


documentation:fabric_loom

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
documentation:fabric_loom [2022/02/05 23:04] – fix + clarification juuzdocumentation:fabric_loom [2023/12/22 14:39] (current) – Remove confusion around loom extracting nested jars. modmuss50
Line 11: Line 11:
   * ''genEclipseRuns'': Installs Eclipse run configurations and creates the run directory if it does not already exist.   * ''genEclipseRuns'': Installs Eclipse run configurations and creates the run directory if it does not already exist.
   * ''vscode'': Generates or overwrites a Visual Studio Code ''launch.json'' file with launch configurations in the ''.vscode'' directory and creates the run directory if it does not already exist.   * ''vscode'': Generates or overwrites a Visual Studio Code ''launch.json'' file with launch configurations in the ''.vscode'' directory and creates the run directory if it does not already exist.
 +  * ''ideaSyncTask'': Generates (but not overrides) the Intellij IDEA launch config, including client and server by default.
   * ''remapSourcesJar'': Only exists if an AbstractArchiveTask ''sourcesJar'' exists. Remaps the output of the ''sourcesJar'' task in place.   * ''remapSourcesJar'': Only exists if an AbstractArchiveTask ''sourcesJar'' exists. Remaps the output of the ''sourcesJar'' task in place.
   * ''runClient'': A JavaExec task to launch Fabric Loader as a Minecraft client.   * ''runClient'': A JavaExec task to launch Fabric Loader as a Minecraft client.
Line 24: Line 25:
 } }
 </code> </code>
 +
 +If you are using splitsource sets in a multi-project build, you will also need to add a dependency for the other projects client sourceset.
 +
 +<code>
 +dependencies {
 + clientImplementation project(":name").sourceSets.client.output
 +}
 +</code>
 +
 +==== Split Client and Common code ====
 +
 +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 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 to split the client and common code.
 +
 +<code>
 +loom {
 + splitEnvironmentSourceSets()
 +
 + mods {
 +        modid {
 +            sourceSet sourceSets.main
 +            sourceSet sourceSets.client
 +        }
 + }
 + }
 +</code>
 +
 +==== 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 <code>fabric.loom.multiProjectOptimisation=true</code> to the gradle.properties file will help decrease build time and memory usage by sharing the Tiny Remapper instance between projects when remapping your output jars.
  
 ==== Options ==== ==== Options ====
Line 58: Line 92:
  // Add a program arg  // Add a program arg
  programArg "--example"  programArg "--example"
 + // Add an environment variable
 + environmentVariable("example", "true")
  // The environment (or side) to run, usually client or server.  // The environment (or side) to run, usually client or server.
  environment = "client"  environment = "client"
Line 86: Line 122:
  source = sourceSets.test  source = sourceSets.test
  }  }
 +
 +                // Example of removing the built-in server configuration
 +                remove server
  }  }
  
Line 122: Line 161:
  enableDependencyInterfaceInjection = true  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)
 } }
  
Line 193: Line 248:
 ==== Resolving issues ==== ==== Resolving issues ====
  
-Loom and/or gradle can sometimes fail due to corrupted cache files. Running ''./gradlew build --refresh-dependencies'' will force gradle and loom to re-download and recreate all of the files. This may take a few minutes but is usually quite successful with resolving cache related issues.+Loom and/or gradle can sometimes fail due to corrupted cache files. Running ''./gradlew build <nowiki>--</nowiki>refresh-dependencies'' will force gradle and loom to re-download and recreate all of the files. This may take a few minutes but is usually quite successful with resolving cache related issues.
  
 ==== Development environment setup ==== ==== Development environment setup ====
Line 207: Line 262:
   - Adds dependencies of Minecraft.   - Adds dependencies of Minecraft.
   - Downloads Minecraft assets.   - Downloads Minecraft assets.
-  - Processes and includes mod-augmented dependencies (and optionally extracts and remaps nested JARs).+  - Processes and includes mod-augmented dependencies.
  
 ==== Caches ==== ==== Caches ====
Line 220: Line 275:
   * ''minecraft'': Defines the version of Minecraft to be used in the development environment.    * ''minecraft'': Defines the version of Minecraft to be used in the development environment. 
   * ''mappings'': Defines the mappings to be used in the development environment.   * ''mappings'': Defines the mappings to be used in the development environment.
-  * ''modCompile'', ''modImplementation'', ''modApi'' and ''modRuntime'': Augmented variants of ''compile'', ''implementation'', ''api'' and ''runtime'' for mod dependencies. Will be remapped to match the mappings in the development environment and has any nested JARs removed. Nested JARs can optionally be extracted and remapped.+  * ''modCompile'', ''modImplementation'', ''modApi'' and ''modRuntime'': Augmented variants of ''compile'', ''implementation'', ''api'' and ''runtime'' for mod dependencies. Will be remapped to match the mappings in the development environment and has any nested JARs removed.
   * ''include'': Declares a dependency that should be included as a jar-in-jar in the ''remapJar'' output. This dependency configuration is not transitive. For non-mod dependencies, Loom will generate a mod JAR with a fabric.mod.json using the name as the mod ID and the same version.   * ''include'': Declares a dependency that should be included as a jar-in-jar in the ''remapJar'' output. This dependency configuration is not transitive. For non-mod dependencies, Loom will generate a mod JAR with a fabric.mod.json using the name as the mod ID and the same version.
  
Line 243: Line 298:
  
 The client run configuration is configured with ''--assetsIndex'' and ''--assetsDir'' program arguments pointing to the loom cache directory containing assets and the index file for the configured version of Minecraft. When running on OSX, the "-XstartOnFirstThread" VM argument is added. The client run configuration is configured with ''--assetsIndex'' and ''--assetsDir'' program arguments pointing to the loom cache directory containing assets and the index file for the configured version of Minecraft. When running on OSX, the "-XstartOnFirstThread" VM argument is added.
 +
  
documentation/fabric_loom.1644102266.txt.gz · Last modified: 2022/02/05 23:04 by juuz