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
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:
| Method | Targets 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):
validateMergedClasses(GraftValidateClassesTask) — Runs before packaging. Inspects every.classfile across all selected targets using ASM and validates all*.mixins.jsonconfigs. Fails the build if incompatible bytecode or unguarded version-specific mixins are detected (see Validation & SPI).mergeMergedMetadata(GraftMergeMetadataTask) — Produces clean, deduplicated metadata files inbuild/graft/merged/merged-metadata/:fabric.mod.json: Unionsmixins,jars(Jar-in-Jar), andentrypointsacross all selected Fabric JARs; appliesfabricDepends(...)overrides; setsaccessWidener.META-INF/neoforge.mods.toml: Unions[[mixins]]and[[accessTransformers]]across all selected NeoForge JARs; rewrites matchingversionRangeentries under[[dependencies.<modId>]]usingneoforgeDepends(...).META-INF/jarjar/metadata.json: Unions NeoForge Jar-in-Jar entries and rewrites their paths fromMETA-INF/jarjar/toMETA-INF/jars/so Fabric and NeoForge share a single copy of each embedded library JAR insideMETA-INF/jars/instead of shipping every JiJ dependency twice!META-INF/services/**: Merges and deduplicates JavaServiceLoaderprovider files across all target JARs andbundle(...)JARs.- Access Wideners / ClassTweakers &
META-INF/accesstransformer.cfg: Deduplicates rules line-by-line across versions while preserving the header.
shadowJarMerged(ShadowJar) — Copies the merged metadata directory first, overlays all target JARs (excluding unmerged raw metadata files) andbundle(...)configurations, relocatesMETA-INF/jarjar/*.jarintoMETA-INF/jars/, and runs yourshadow { ... }configuration.optimizeJarMerged(optional, via Machete) — Automatically registered whenorg.redlance.dima_dencep.gradle.macheteis 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: StringvalidateTask: 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) producingbuild/libs/<archiveBaseName>-<version>.jarwith source-file & LVT stripping enabled by default. - Points
handle.outputandassembleat 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).