Skip to main content

Universal JARs (combine)

Cloche produces one finalJar per leaf target (26.2:fabric, 26.2:neoforge, 26.3:fabric, 26.3:neoforge, ...).

With graft.combine(name) { ... }, you can assemble any subset of those targets into a single universal JAR — built around ShadowJar — whether you want:

  • One multi-loader JAR per Minecraft version (fromVersion("26.3")),
  • One multi-version JAR per loader (fromLoader("fabric")),
  • Or one universal JAR covering all versions and all loaders (fromAllTargets() / fromVersions("26.2", "26.3")).

Basic example​

minecraft/build.gradle.kts
val shadowBundle by configurations.creating {
isTransitive = false
}

dependencies {
shadowBundle(project(":core"))
}

graft {
// ... targets ...

combine("merged") {
fromAllTargets()
bundle(shadowBundle)
archiveBaseName = "MyMod-universal"

fabricDepends(
"minecraft" to ">=26.1 <=26.3",
"fabricloader" to ">=0.19.5",
)
neoforgeDepends(
"minecraft" to "[26.1,26.4)",
"neoforge" to "[26.1.2.15,)",
)

shadow {
relocate("com.example.shaded", "org.mymod.shaded")
}
}
}

In Groovy DSL, fabricDepends and neoforgeDepends accept named map arguments:

fabricDepends(minecraft: ">=26.1 <=26.3", fabricloader: ">=0.19.5")
neoforgeDepends(minecraft: "[26.1,26.4)", neoforge: "[26.1.2.15,)")

Selecting targets​

You can register as many combine("...") blocks as you want in one project. Each block selects its input targets via one or more selectors:

MethodTargets selected
fromVersion("26.3")All leaf targets registered under Minecraft 26.3 (e.g. 26.3:fabric + 26.3:neoforge).
fromVersions("26.2", "26.3")All leaf targets across the listed Minecraft versions.
fromLoader("fabric")All leaf targets for that loader across all registered versions.
fromAllTargets()Every registered leaf target across all versions and loaders.
from(targetA, targetB)Explicit Cloche MinecraftTarget instances.

Use bundle(configuration) to embed additional non-Minecraft Gradle configurations (such as a shared :core subproject) into the ShadowJar.

The 3-stage combine pipeline​

For combine("merged"), Graft registers and wires three tasks (plus an optional fourth when Machete is applied):

  1. validateMergedClasses (GraftValidateClassesTask) — Runs before packaging. Inspects every .class file across all selected targets using ASM and validates all *.mixins.json configs. Fails the build if incompatible bytecode or unguarded version-specific mixins are detected (see Validation & SPI).
  2. mergeMergedMetadata (GraftMergeMetadataTask) — Produces clean, deduplicated metadata files in build/graft/merged/merged-metadata/:
    • fabric.mod.json: Unions mixins, jars (Jar-in-Jar), and entrypoints across all selected Fabric JARs; applies fabricDepends(...) overrides; sets accessWidener.
    • META-INF/neoforge.mods.toml: Unions [[mixins]] and [[accessTransformers]] across all selected NeoForge JARs; rewrites matching versionRange entries under [[dependencies.<modId>]] using neoforgeDepends(...).
    • META-INF/jarjar/metadata.json: Unions NeoForge Jar-in-Jar entries and rewrites their paths from META-INF/jarjar/ to META-INF/jars/ so Fabric and NeoForge share a single copy of each embedded library JAR inside META-INF/jars/ instead of shipping every JiJ dependency twice!
    • META-INF/services/**: Merges and deduplicates Java ServiceLoader provider files across all target JARs and bundle(...) JARs.
    • Access Wideners / ClassTweakers & META-INF/accesstransformer.cfg: Deduplicates rules line-by-line across versions while preserving the header.
  3. shadowJarMerged (ShadowJar) — Copies the merged metadata directory first, overlays all target JARs (excluding unmerged raw metadata files) and bundle(...) configurations, relocates META-INF/jarjar/*.jar into META-INF/jars/, and runs your shadow { ... } configuration.
  4. optimizeJarMerged (optional, via Machete) — Automatically registered when org.redlance.dima_dencep.gradle.machete is applied (see below).

By default (attachToAssemble = true), the final task is wired into assemble (and therefore build).

CombinedJarHandle​

graft.combine("merged") { ... } returns a CombinedJarHandle (also retrievable later with graft.combined("merged")), useful for publishing or Modrinth/CurseForge upload plugins:

val merged = graft.combine("merged") {
fromAllTargets()
}

modrinth {
uploadFile.set(merged.output) // Points to optimized JAR if Machete is active, else ShadowJar
}

Available properties on CombinedJarHandle:

  • name: String
  • validateTask: TaskProvider<GraftValidateClassesTask>
  • mergeMetadataTask: TaskProvider<GraftMergeMetadataTask>
  • shadowTask: TaskProvider<ShadowJar>
  • output: Provider<RegularFile>

Optional Machete optimization​

If you apply the Machete Gradle plugin (id("org.redlance.dima_dencep.gradle.machete")) to the same project, Graft automatically:

  • Sets shadowJar<Name>'s classifier to "fat".
  • Registers optimizeJar<Name> (OptimizeJarsTask) producing build/libs/<archiveBaseName>-<version>.jar with source-file & LVT stripping enabled by default.
  • Points handle.output and assemble at the optimized JAR.

You can customize Machete's settings via optimize { ... }, or disable it for a specific combine block with optimizeEnabled = false. Machete is strictly optional — if the plugin is not applied, Graft never loads Machete classes (safe in both Kotlin and Groovy DSLs).