documentation:fabric_loom
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
documentation:fabric_loom [2019/06/07 21:39] – [Default configuration] jamieswhiteshirt | documentation:fabric_loom [2023/12/22 14:39] (current) – Remove confusion around loom extracting nested jars. 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 tasks ==== |
- | + | ||
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | ==== Default tasks ==== | ||
- | |||
- | * '' | ||
- | * '' | ||
* '' | * '' | ||
- | * '' | + | * '' |
- | * '' | + | * '' |
* '' | * '' | ||
- | | + | * '' |
- | | + | * '' |
- | * '' | + | * '' |
- | * '' | + | * '' |
* '' | * '' | ||
* '' | * '' | ||
- | ==== Default configuration | + | ==== Depending on Sub Projects |
- | * Applies | + | When setting up a multi-project build that depenends on another loom project you should use the '' |
- | * Adds the following Maven repositories: | + | |
- | * Configures '' | + | |
- | * Configures the '' | + | |
- | * Adds '' | + | |
- | * Adds the output of '' | + | |
- | * If an AbstractArchiveTask '' | + | |
- | Run configurations are generated from the fabric-installer.json file of Fabric Loader if it installed as a dependency. | + | < |
+ | dependencies { | ||
+ | implementation project(path: | ||
+ | } | ||
+ | </ | ||
- | ==== Publishing ==== | + | 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. |
- | ==== Useful task types ==== | + | < |
+ | dependencies { | ||
+ | clientImplementation project(": | ||
+ | } | ||
+ | </ | ||
- | * '' | + | ==== Split Client and Common code ==== |
- | * '' | + | |
- | ==== The development environment ==== | + | For years a common source of server crashes has been from mods accidentally calling client only code when installed on a server. |
- | Loom does quite a few things behind the scenes to create a development environment with Minecraft. | + | 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), | ||
+ | |||
+ | < | ||
+ | loom { | ||
+ | splitEnvironmentSourceSets() | ||
+ | |||
+ | mods { | ||
+ | modid { | ||
+ | sourceSet sourceSets.main | ||
+ | sourceSet sourceSets.client | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== 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 for IDE's. By default only set to true for the root project. | ||
+ | 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 mod jar to this task, the include configuration should be used for maven libraries and mods. | ||
+ | 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 added. (https:// | ||
+ | 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 " | ||
+ | |||
+ | // 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 to aid with depending on a specific fabric api version. | ||
+ | modImplementation fabricApi.module(" | ||
+ | |||
+ | // Depend on a loom sub project by using the namedElements configuration. | ||
+ | implementation project(path: | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Resolving issues ==== | ||
+ | |||
+ | Loom and/or gradle can sometimes fail due to corrupted cache files. Running '' | ||
+ | |||
+ | ==== Development environment setup ==== | ||
+ | |||
+ | Loom is designed to work out of the box by simply setting up a workspace in the user's IDE of choice. It does quite a few things behind the scenes to create a development environment with Minecraft: | ||
- Downloads the client and server jar from official channels for the configured version of Minecraft. | - Downloads the client and server jar from official channels for the configured version of Minecraft. | ||
Line 52: | 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. | ||
- Downloads Minecraft assets. | - Downloads Minecraft assets. | ||
- | - Remaps | + | - Processes and includes |
==== Caches ==== | ==== Caches ==== | ||
* '' | * '' | ||
- | * '' | + | * '' |
* '' | * '' | ||
* '' | * '' | ||
+ | |||
+ | ==== 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