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/01/20 13:43] modmuss50documentation: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 41: Line 75:
  // When enabled transitive access wideners will be applied from dependencies.  // When enabled transitive access wideners will be applied from dependencies.
  enableTransitiveAccessWideners = true  enableTransitiveAccessWideners = true
- // When enabled interface injection will be enabled 
- enableInterfaceInjection = true 
  // When enabled log4j will only be on the runtime classpath, forcing the use of SLF4j.  // When enabled log4j will only be on the runtime classpath, forcing the use of SLF4j.
  runtimeOnlyLog4j = false  runtimeOnlyLog4j = false
Line 60: 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 88: Line 122:
  source = sourceSets.test  source = sourceSets.test
  }  }
 +
 +                // Example of removing the built-in server configuration
 +                remove server
  }  }
  
Line 119: Line 156:
  }  }
  }  }
 +
 + 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)
 } }
  
Line 155: Line 213:
  
  // Remap a mod from maven and apply to gradle's implementation configuration  // Remap a mod from maven and apply to gradle's implementation configuration
 + // (Minor detail: it's not exactly applied *to* the configuration, but a clone of it intended for mod dependencies)
  modImplementation "net.fabricmc.fabric-api:fabric-api:0.46.2+1.18"  modImplementation "net.fabricmc.fabric-api:fabric-api:0.46.2+1.18"
  
Line 166: Line 225:
  modCompileOnlyApi "net.fabricmc.fabric-api:fabric-api:0.46.2+1.18"  modCompileOnlyApi "net.fabricmc.fabric-api:fabric-api:0.46.2+1.18"
  
- // Remap a mod from maven and apply to gradle'runtimeOnlyApi configuration+ // Remap a mod from maven and apply to gradle'runtimeOnly configuration
  modRuntimeOnly "net.fabricmc.fabric-api:fabric-api:0.46.2+1.18"  modRuntimeOnly "net.fabricmc.fabric-api:fabric-api:0.46.2+1.18"
  
Line 189: 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 203: 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 216: 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 239: 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.1642686211.txt.gz · Last modified: 2022/01/20 13:43 by modmuss50