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 aminecraftVersion, aloaderVersion, its own GradleSourceSet, run configurations, and outputfinalJar. - 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:
- Finds all leaf targets that transitively depend on
C. - Inspects the full Minecraft + loader + common-dependency bytecode of every one of those leaf targets.
- 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).
- Compiles
C'sSourceSetagainst 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 by26.1,26.2,26.3): neither incompatible overload exists in the API stub.javacimmediately refuses to compile any call to them insrc/main, forcing you to abstract the call behind an SPI or compat layer. - In
src/pre263(only inherited by26.1and26.2): the stub is the intersection of26.1and26.2only, soPredicate<Identifier>andmulPose(Quaternionfc)are present and compile cleanly. - In
src/26.3/common(only inherited by26.3:fabricand26.3:neoforge): the stub is the intersection of26.3:fabricand26.3:neoforge, soResourceManager.Selectoris available.
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:
- Cloche's
@Expect/@Actualannotations (fromnet.msrandom.multiplatform.annotations): a compile-time stub replacement where Cloche swaps a stub class incommonfor the target-specific@Actualclass 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
.classfiles with the exact same class name!
- Java
ServiceLoader(SPI) — defining a plain interface insrc/mainand registering loader/version-specific implementations underMETA-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 apiCloche'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.