Skip to main content

Targets & API Stubs

Common vs. leaf targets​

Cloche distinguishes two kinds of targets:

  • Leaf targets (fabric, neoforge, forge) represent concrete mod artifacts targeting a single (Minecraft version, mod loader) pair. Each leaf target has a minecraftVersion, a loaderVersion, its own Gradle SourceSet, run configurations, and output finalJar.
  • Common targets (common, common("name")) represent shared source sets that are never shipped on their own. Instead, their compiled classes and resources are inherited by every leaf target that depends on them.

Default root common target​

Every multi-target Cloche project automatically has a root common target backed by Gradle's standard main source set (src/main/java and src/main/resources). Every leaf target implicitly inherits from common — you do not need to write dependsOn(common).

Named targets and colons​

You can declare multiple targets of the same kind by passing a name string. Cloche uses : as a hierarchical separator in target names:

cloche {
common() // sourceSet "main" -> src/main
common("26.3:common") // sourceSet "26.3Common" -> src/26.3Common (unless overridden)

fabric("26.3:fabric") {
minecraftVersion = "26.3"
loaderVersion = "0.19.5"
dependsOn(common("26.3:common"))
}

neoforge("26.3:neoforge") {
minecraftVersion = "26.3"
loaderVersion = "26.3.0.1-alpha"
dependsOn(common("26.3:common"))
}
}

By default, Cloche derives the Gradle SourceSet name by camel-casing the target name (26.3:fabric → 26.3Fabric), and Gradle looks in src/<sourceSetName>/java. Graft overrides this to the cleaner nested layout src/26.3/fabric/java.

Target inheritance (dependsOn)​

Common targets can depend on other common targets, and leaf targets can depend on any number of common targets:

common (src/main)
/ | \
fabric pre263 (26.1+26.2) neoforge
/ \ / \ / \
26.1:fabric 26.2:fabric 26.2:neoforge 26.1:neoforge

Inheritance propagates:

  • Compiled classes and resources (packaged into each inheriting leaf target's JAR).
  • Dependencies declared inside the common target's dependencies { ... } block.
  • Access Wideners / ClassTweakers declared on the common target.
  • Mixins declared on the common target.

How API Stub Intersection works​

This is Cloche's killer feature. When you write Java code in src/main (or any intermediate common("...") target), which Minecraft JAR does javac compile against?

A project with 26.1:fabric, 26.2:fabric, 26.3:fabric, and 26.3:neoforge has four different Minecraft + loader classpaths. Cloche cannot simply pick one of them — if it picked 26.3, your common code might call a method that doesn't exist in 26.1, or reference a NeoForge-only patch that doesn't exist on Fabric.

Instead, for every common target C, Cloche runs a GenerateStubApi (createCommonApiStub) task:

  1. Finds all leaf targets that transitively depend on C.
  2. Inspects the full Minecraft + loader + common-dependency bytecode of every one of those leaf targets.
  3. Computes the structural intersection:
    • Only classes present in all leaf targets survive.
    • Only methods and fields with matching descriptors present in all leaf targets survive.
    • Only interfaces and superclasses common to all leaf targets survive.
    • Method bodies are stripped (keeping bytecode stubs purely for javac / IDE resolution).
  4. Compiles C's SourceSet against that intersection stub JAR.

What this buys you​

Suppose in Minecraft 26.3, ResourceManager.listResources changes its second parameter from Predicate<Identifier> to ResourceManager.Selector, and PoseStack.mulPose(Quaternionfc) is removed.

  • In src/main (shared by 26.1, 26.2, 26.3): neither incompatible overload exists in the API stub. javac immediately refuses to compile any call to them in src/main, forcing you to abstract the call behind an SPI or compat layer.
  • In src/pre263 (only inherited by 26.1 and 26.2): the stub is the intersection of 26.1 and 26.2 only, so Predicate<Identifier> and mulPose(Quaternionfc) are present and compile cleanly.
  • In src/26.3/common (only inherited by 26.3:fabric and 26.3:neoforge): the stub is the intersection of 26.3:fabric and 26.3:neoforge, so ResourceManager.Selector is available.
Split client vs. server targets on Fabric

By default on Fabric, Cloche can split client and common sources (like Loom's splitEnvironmentSourceSets()). Calling includedClient() on a fabric target merges the client Minecraft JAR into the target's main compilation so client classes (net.minecraft.client.*) are directly visible in common and fabric sources — matching NeoForge's unified classpath. Graft calls includedClient() automatically on every Fabric target.

Bridging platform differences: @Expect vs. Java SPI​

Cloche supports two ways for common code to call loader- or version-specific implementations:

  1. Cloche's @Expect / @Actual annotations (from net.msrandom.multiplatform.annotations): a compile-time stub replacement where Cloche swaps a stub class in common for the target-specific @Actual class inside each leaf JAR.
    • Works well if you publish separate JARs per loader and per Minecraft version.
    • Incompatible with universal JARs, because two targets produce two different .class files with the exact same class name!
  2. Java ServiceLoader (SPI) — defining a plain interface in src/main and registering loader/version-specific implementations under META-INF/services/<interface> with distinct class names (e.g., PalCompat261, PalCompat262, PalCompat263).
    • Works identically for both per-target JARs and merged universal JARs.
    • Recommended whenever you use Graft's combine(...) pipeline (see Validation & SPI).

singleTarget mode​

If a Gradle subproject only targets a single Minecraft + loader environment (for example, a pure Minecraft helper library like :emotesMc that does not need multiple loaders), Cloche offers cloche.singleTarget { ... }:

cloche {
singleTarget {
fabric {
minecraftVersion = "26.3"
loaderVersion = "0.19.5"
}
}
}

In singleTarget mode, the target uses the standard main source set directly (src/main) instead of creating a secondary source set.

singleTarget { fabric } leaks fabric-loader onto api

Cloche's singleTarget { fabric { ... } } adds net.fabricmc:fabric-loader to the project's api configuration. If another non-Fabric module (such as NeoForge or Paper) depends on that subproject directly, fabric-loader leaks onto its classpath. Graft's vanillaLibrary wraps singleTarget with a clean libraryElements capability to avoid this.