Skip to main content

Vanilla Libraries (vanillaLibrary)

In multi-platform repositories (like Emotecraft, which has :emotesAPI, :emotesMc, :minecraft, and :paper), you often want a lightweight subproject that compiles against vanilla Minecraft classes (packets, components, Identifier, etc.) without depending on Fabric API or NeoForge.

In raw Cloche, using cloche.singleTarget { fabric { ... } } gets you a vanilla Minecraft classpath quickly, but Cloche adds net.fabricmc:fabric-loader to the module's api configuration. If :minecraft (NeoForge targets) or :paper depends on that subproject directly, fabric-loader leaks onto their classpaths and causes conflicts.

Graft's vanillaLibrary { ... } solves this cleanly.

Configuring a vanilla library module​

emotesMc/build.gradle.kts
plugins {
id("org.redlance.graft")
}

graft {
vanillaLibrary {
minecraftVersion = "26.3"
fabricLoaderVersion = "0.19.5"

// Exposed to both this module's compilation AND its clean libraryElements variant
api(project(":emotesAPI"))
compileOnly("org.jetbrains:annotations:26.0.2")
}
}

What vanillaLibrary does​

  1. Configures cloche.singleTarget { fabric { ... } } with your minecraftVersion and fabricLoaderVersion (with withSourcesJar() enabled by default).
  2. Disables fabric.mod.json generation (since pure libraries are not standalone mods).
  3. Adds FMLModType: GAMELIBRARY to the JAR manifest (configurable via gameLibraryManifest = false) so NeoForge loads it cleanly alongside mods.
  4. Publishes an outgoing Gradle consumable configuration named libraryElements carrying:
    • The compiled JAR (tasks.named("jar")),
    • Only the dependencies declared via api(...) / apiDependencies { ... } (never fabric-loader!),
    • Capability "${project.group}:${project.name}-${capabilitySuffix}:${project.version}" (default suffix "lib").

Consuming a vanillaLibrary from sibling modules​

In your :minecraft (Fabric + NeoForge) or :paper module, reference the clean variant with graft.graftLibrary(":emotesMc"):

minecraft/build.gradle.kts
graft {
common {
dependencies {
api(graft.graftLibrary(":emotesMc")) {
excludeMinecraftLibs()
}
}
}
}

Or in Groovy DSL:

minecraft/build.gradle
graft {
common {
dependencies {
api(graft.graftLibrary(":emotesMc")) {
graft.excludeMinecraftLibs(it)
}
}
}
}

You can also use the Kotlin extension project(":emotesMc").asGraftLibrary() directly inside any dependencies { ... } block.

VanillaLibrarySpec options​

Property / MethodDefaultDescription
modIdproject.name.lowercase()Passed to cloche.metadata.modId.
minecraftVersion(required)Minecraft version to compile against.
fabricLoaderVersion(required)Fabric Loader version used internally by Cloche's single-target setup (never exposed on libraryElements).
withSourcesJartrueAttaches a sources JAR to the target.
gameLibraryManifesttrueAdds FMLModType: GAMELIBRARY to the JAR manifest.
capabilitySuffix"lib"Capability suffix for libraryElements (<group>:<name>-<suffix>:<version>).
api(notation, configure?)—Adds an api dependency to both compilation and libraryElements.
compileOnly(notation, configure?)—Adds a compileOnly dependency.
apiDependencies { ... }—Full DependencyHandler block scoped to libraryApi.
fabric { ... }—Escape hatch to customize the underlying Cloche FabricTarget.