Forgix Gradle Plugin

repository·main·Indexed 41 days ago

https://github.com/pacifistmc/forgix

A Gradle plugin for Minecraft modders that combines multiple modloaders (such as Fabric, Forge, Quilt, and NeoForge) or multiple Minecraft versions into a single JAR file. It utilizes JVM class-loading behavior to prevent interference between different modloader entry points and supports a wide range of platforms including Bukkit, Spigot, Paper, and Velocity.

Tokens
1.4K
Snippets
6
Records
6
Agent score
2%

What's inside Forgix

  1. How multiversion merging works

    main

    Forgix can merge the same mod built for several different Minecraft versions into a single jar using the mergeVersions task. This is useful for creating a single "universal" jar that works across multiple game versions.

    MultiversionConfiguration options:

    • inputJars (FileCollection): Sets the jars to merge, one for each Minecraft version. At least two jars are required.
    • archiveBaseName (String): Sets the base name for the merged archive. Defaults to the root project's name.
    • archiveClassifier (String): Sets the classifier for the merged archive. Defaults to multi.
    • archiveVersion (String): Sets the version for the merged archive. Defaults to the root project's version.
    • destinationDirectory (Directory): Sets the directory where the merged jar will be placed. Defaults to build/forgix/multiversion in the root project.
    forgix {
        multiversion {
            inputJars = files(
                    project(":1.20.1").tasks.remapJar.archiveFile,
                    project(":1.21.1").tasks.remapJar.archiveFile
            )
        }
    }
  2. Install the Forgix Gradle plugin

    main

    To use Forgix, apply the plugin to your root build.gradle file. You can use either the modern Plugins DSL or the legacy buildscript application method. Replace <version> with the latest version from the Forgix Releases page.

    ### Groovy (Plugins DSL)
    ```groovy
    plugins {
        id "io.github.pacifistmc.forgix" version "<version>"
    }

    Kotlin (Plugins DSL)

    plugins {
        id("io.github.pacifistmc.forgix") version "<version>"
    }
  3. Configure the Forgix root container

    main

    The forgix configuration block allows you to control the output and execution of the merging process.

    Available options:

    • silence (Boolean): Whether to silence the thank you message. Defaults to false.
    • autoRun (Boolean): Whether to automatically run the mergeJars task (and mergeVersions if multiversion is configured) during the assemble or build tasks. Defaults to false.
    • archiveBaseName (String): Sets the base name for the merged archive. Defaults to the root project's name.
    • archiveClassifier (String): Sets the classifier for the merged archive. Defaults to a string joining all the platforms.
    • archiveVersion (String): Sets the version for the merged archive. Defaults to the root project's version.
    • destinationDirectory (Directory): Sets the directory where the merged jar will be placed. Defaults to build/forgix in the root project.
    forgix {
        silence = false
        autoRun = true
        archiveClassifier = "all-platforms"
        archiveVersion = "1.0.0"
        destinationDirectory = layout.projectDirectory.dir("build/forgix")
    }
  4. Configure modloaders and plugins

    main

    Forgix supports various modloaders and plugin platforms. You can call the method with no arguments to use default detection, or provide a configuration block to specify a custom inputJar if automatic detection fails.

    Supported platforms:

    • fabric()
    • forge()
    • quilt()
    • neoforge()
    • liteloader()
    • rift()
    • plugin()
    • bukkit()
    • spigot()
    • paper()
    • sponge()
    • foila()
    • bungeecoord()
    • waterfall()
    • velocity()

    Loader Configuration options:

    • inputJar (RegularFileProperty): Sets the input jar file to be merged. If not specified, Forgix attempts to automatically detect the jar file.
    forgix {
        // Simple usage with defaults
        fabric()
    
        // With custom input jar
        forge {
            inputJar = project(":forge").tasks.shadowJar.archiveFile
        }
    }
  5. Merge loaders and versions together

    main

    You can combine both features by first running mergeJars for each Minecraft version to create platform-specific merged jars, and then passing those resulting jars into the multiversion configuration.

    forgix {
        multiversion {
            inputJars = files(
                    "1.20.1/build/forgix/yourmod-1.20.1-fabric-forge.jar",
                    "1.21.1/build/forgix/yourmod-1.21.1-fabric-forge.jar"
            )
        }
    }
  6. Use the generic merge method for custom loaders

    main

    If you are using a custom modloader or project that is not explicitly supported, use the merge("projectName") method. The project name must match the name of the subproject you wish to include.

    forgix {
        // Simple usage with defaults
        merge("customLoader")
    
        // With configuration
        merge("customLoader") {
            inputJar = project(":customLoader").tasks.shadowJar.archiveFile
        }
    }