Skip to content

About

Gradle plugin for Cleanroom development, and vanilla usage.

Resources

Contributing

Security policy

Stars

22 stars

Watchers

1 watching

Forks

Repository files navigation

CleanroomGradle

Gradle plugin for Cleanroom Loader development and Cleanroom-targeted mod development. The current release is 0.17.0.

Usage

The settings plugin adds the following maven repositories:

  • Maven Central
  • CleanroomMC (proxies MinecraftForge's maven)
  • Mojang Libraries

The project plugin registers the main toolchain and development tasks.

pluginManagement {
    repositories {
        maven {
            url = 'https://maven.cleanroommc.com'
        }
        gradlePluginPortal()
    }
}

plugins {
    id 'com.cleanroommc.cleanroomgradle.settings' version '0.17.0'
    id 'org.gradle.toolchains.foojay-resolver-convention' version '1.0.0' // If auto-provisioning is needed
}
plugins {
    id 'java'
    id 'com.cleanroommc.cleanroomgradle'
}

Modes

The plugin stays inert until an environment is registered.

Loader and standalone vanilla development still use cleanroom.mode = 'loader' and cleanroom.mode = 'vanilla'.

Whereas a mod workspace (userdev) is activated by its dependency:

dependencies {
    // Selects Cleanroom version 0.7.0-alpha
    implementation cleanroom.userdev('0.7.0-alpha') {
        accessTransformers.from('src/main/resources/META-INF/modid_at.cfg') // Optional
    }
}

A stratum project is selected by cleanroom.stratum { }. See Strata.

Configuration

cleanroom {
    caches {
        // Global cache
        directory = layout.projectDirectory.dir('.gradle/cleanroom-shared')
        // 1.12.2 toolchain cache
        versionDirectory = layout.projectDirectory.dir('.gradle/cleanroom-shared/versions/1.12.2')
        // Project local generated/intermediate data
        localDirectory = layout.buildDirectory.dir('cleanroom_gradle')
        // Loader defaults false; other modes default true
        discardIntermediates = true
    }

    mappings {
        // Optional editable Tiny v2 source at <directory>/mappings.tiny
        namesDirectory = layout.projectDirectory.dir('mappings')
    }

    loader {
        accessTransformers.from('src/main/resources/META-INF/accesstransformer.cfg')
        sideAnnotationStrippers.from('src/main/resources/META-INF/side_annotation_stripper.cfg')
        intermediateRuns = true
    }
}
  • The unsuffixed vanilla tasks always target Minecraft 1.12.2 and resolve that version through Mojang's launcher manifest into the shared cache.
  • Named vanilla environments are the way to work with other Minecraft versions.
    • Available in every project mode. Override the Java launcher for a named environment with javaVersion.
  • For several versions in one project, declare them together:
cleanroom {
    vanilla {
        "1.4.7" {
            client {
                args '--demo'
                maxHeapSize = '2G'
            }
            server {
                args '--custom-server-argument'
            }
        }
        "26.1" {
            javaVersion = 25 // Defaults to launcher metadata otherwise
        }
    }
}

Letters, numbers, dots, underscores, and hyphens are accepted in environment names.

An alias can target a different version:

cleanroom {
    vanilla {
        legacy {
            version = '1.4.7'
        }
    }
}

That creates runLegacyClient while targeting Minecraft 1.4.7.

Named environments share downloaded assets and per-version metadata/JARs, but use isolated dependency configurations, extracted natives, and run directories. Launcher metadata supplies each vanilla client's main class and arguments.

Runs

Use cleanroom.runs to configure existing runs and create custom runs. Each short name maps to run followed by the name with its first letter capitalized.

cleanroom {
    runs {
        client { // Configures existing "runClient"
            configure {
                username = 'Developer'
                jvmArgs '-Dmixin.debug.export=true'
            }
        }
        custom { // Creates new "runCustom"
            configure {
                username = 'Tester'
                maxHeapSize = '3G'
                args '--demo'
            }
            inherit = 'client'
        }
    }
}
  • inherit can appear anywhere in the outer block and can reference a run declared later.
  • The parent supplies its built-in launch setup and its configure blocks before the child's configure blocks execute.
  • Inheritance can follow a chain of runs. Each block configures the destination task; name refers to that task.
Runs Availability
client, server Userdev mode and strata that declare a Cleanroom version
vanillaClient, vanillaServer Any selected project mode
cleanroomClient, cleanroomServer, cleanroomNsightClient Loader mode
srgClient, srgServer, reobfSrgClient, reobfSrgServer, mcpClient, mcpServer Loader mode with loader.intermediateRuns = true
<name>Client, <name>Server A declared named vanilla environment

Kotlin DSL can use the typed configure overload to access the full task API.

import com.cleanroommc.gradle.api.task.mc.RunMinecraft

cleanroom {
    runs {
        register("custom") {
            inherit.set("client")
            configure(RunMinecraft::class.java) {
                username.set("Tester")
                jvmArgs("-Dexample=true")
            }
        }
    }
}

Mod Artifacts

assemble produces both jars in build/libs. Maven uses different classifiers.

Names Build Artifact Maven Artifact
MCP <name>-<version>-mcp.jar <artifactId>-<version>.jar
SRG <name>-<version>.jar <artifactId>-<version>-srg.jar

The MCP jar is what components.java carries.

  • from components.java publishes it as the module's main artifact
  • A project dependency on this module resolves to it
plugins {
    id 'maven-publish'
}

publishing {
    publications {
        mod(MavenPublication) {
            // Publishes the main (MCP named) artifact
            from components.java
            // If you want to publish the reobfuscated artifact also
            artifact(tasks.reobfJar) {
                classifier = 'srg'
            }
        }
    }
}

Mod Descriptors

Cleanroom 0.8.0+ reads mod.json at the root of a mod jar. Write it by hand in the main resources, or declare it in the buildscript:

cleanroom {
    mod {
        id = 'modid'
        name = 'Example Mod'
        summary = 'Example Mod.'
        license = 'LGPL-3.0-only'
        author 'CleanroomMC'
        author('CleanroomMC') { role = 'Owner' }
        links.put 'issues', 'https://github.com/example/modid/issues'
        requires 'jei', '[4.16,)'
        optional('jei') { version = '[4.16,)'; side = 'client' }
        mixins.add 'mixins.modid.json'
        checkForTamper = true
        custom.put 'othermod:tab', [icon: 'minecraft:stone']
    }
}
  • writeModDescriptor writes the file into the main resources. Unset members are left out.
  • version defaults to the project version.
  • accessTransformers defaults to the userdev accessTransformers files that sit at META-INF/<name> in the main resources.
  • The block and a hand-written mod.json together fail the build.
  • A hand-written mod.json or stratum.json at the resources root has ${version} replaced with the project version. Nothing else is expanded, and mcmod.info is untouched.

jar fails with a report for each problem Cleanroom would have with the jar at launch:

Problem Fix
Two concrete classes implement one of Mod, ClientMod, ServerMod, Primer Keep one, make the others abstract
One class implements two of them One class per interface
A class implements one and the jar has no mod.json Add mod.json
The jar holds mod.json and stratum.json Remove stratum.json
mod.json sets primer and no class implements Primer Add the Primer, or remove primer
ModType, FMLAT or MixinConfigs in the manifest beside mod.json Move ATs to "accessTransformers" and Mixin configs to "mixins". Cleanroom ignores all three for a Cleanroom mod
version still holds ${, or is unspecified Use ${version}, and set the project version
A value Cleanroom rejects, such as a bad id, a member of the wrong type, an unknown side or kind, a bare version range, an unnamespaced custom key or an instance path outside the game directory As the report says

reobfJar renames the access transformers that mod.json lists to SRG names, or those FMLAT lists in a jar without mod.json.

checkForTamper

With "checkForTamper": true, reobfJar writes META-INF/cleanroom.digest last. Cleanroom marks the mod as modified when the jar's content no longer matches it.

  • The MCP jar gets no digest, since Cleanroom skips the check in development.
  • A later reobfJar.doLast, or any step that rewrites the jar afterwards such as signing, leaves the digest stale, and the mod then reads as modified.

Strata

A stratum is a jar of data and assets with stratum.json for Cleanroom 0.8.0+. It is a project of its own, without the java plugin:

plugins {
    id 'com.cleanroommc.cleanroomgradle'
}

version = '1.0.0'

cleanroom {
    stratum('0.8.0') {
        id = 'examplepack'
        name = 'Example Pack'
        priority = 10
    }
}
src/main/resources/
    data/examplepack/recipes/...
    assets/examplepack/textures/...
  • gradlew build packs src/main/resources and stratum.json into build/libs/<archivesName>-<version>.jar.
  • gradlew runClient and gradlew runServer launch the selected Cleanroom version with the built pack on the classpath. Use stratum { } if you only need to build the pack.
  • Without id, the block only selects the mode, and src/main/resources/stratum.json has to exist.
  • The block takes the members of cleanroom.mod { } that a stratum allows: id, version, name, summary, description, license, author, contributor, credits, links, art, requires, optional, conflicts, before, after, provides, priority, compatibleSince { saves } and custom.
  • jar fails when the jar holds no stratum.json, holds mod.json or a .class file, or has an unresolved version.
  • Applying the java plugin fails, and so does cleanroom.stratum { } in a userdev project.

A userdev project runs with the stratum through a project dependency:

dependencies {
    runtimeOnly project(':examplepack')
}

Mixin Refmap

Name the refmap in gradle.properties to have one generated for the main source set:

cg.userdev.refmap = mixins.modid.refmap.json
  • The Mixin and MixinExtras annotation processors are added at the versions the selected Cleanroom uses.
  • The refmap is written into the class output, so both jars carry it. The Mixin config has to name the same file in "refmap".

Deobfuscation

Wrap a SRG-named dependency in deobf(...) to have it deobfuscated before reaching the classpath:

dependencies {
    implementation deobf('net.test:other-artifact:1.0.0')
    // Local jars work the same way
    implementation deobf(files('libs/other-mod.jar'))
    implementation deobf(fileTree('libs') { include '*.jar' })
}

Any repository Gradle can resolve a module from is supported, as are files(...) and fileTree(...). A local jar is renamed against Minecraft and Cleanroom only, since a file carries no dependencies of its own.

In loader mode deobf(...) cannot be declared on the main compile classpath, that is implementation,compileOnly or api.

Renaming there needs the SRG-named Cleanroom jar, which is built from the main compile classpath, and that would be a cycle. Use a runtime or test configuration instead, such as runtimeOnly.

Kotlin DSL cannot see deobf(...) as a bare function inside a dependencies block. Use cleanroom.deobf(...) there instead.

Jar-in-Jar

In userdev mode with Cleanroom 0.8.0+, declare libraries on jij to nest them, with their runtime dependencies, into reobfJar output:

dependencies {
    jij project(':api')
    jij cleanroom.jij.file('libs/x.jar', 'com.foo:x:1.2')
    jij deobf('net.test:library:1.0') // nests the SRG jar, compiles against MCP
}

cleanroom {
    jij {
        acknowledgeAgent 'org.foo:profiler'
        acknowledgeSystemLoader 'org.foo:legacy'
    }
}
  • jij also puts the library on the compile and runtime classpaths.
  • Each jar nests byte-identical at META-INF/jij/<group>/<name>-<version>[-<classifier>].jar, beside a .meta metadata file holding its identity, the version range it accepts and what required it.
  • Only libraries nest. Mods, Forge mods, coremods and tweakers fail the build when declared, and are skipped with a warning when reached transitively. Declare those on compileOnly or runtimeOnly and require them in mod.json.
  • Libraries Cleanroom ships fail the build when declared. Every classpath is pinned to Cleanroom's versions, so shade and relocate with Shadow when the mod needs another one.
  • A plain jar with no Maven-Artifact in its manifest needs coordinates from cleanroom.jij.file.
  • A userdev subproject nests its reobfJar output.
  • runClient and runServer hand the same jars to Bedrock as nested sources of the mod.
  • The POM marks directly declared jij dependencies optional.
  • gradlew dependencies --configuration jijClasspath shows the graph that is nested.

Toolchain

Area Tasks
Diagnostics cleanroomInfo
Vanilla runVanillaClient, runVanillaServer (decompile<name> and run<name>Client/Server for named environments)
MCP importMcpNames
Stage Runs runSrgClient, runSrgServer, runReobfSrgClient, runReobfSrgServer, runMcpClient, runMcpServer enabled via loader.intermediateRuns
Loader setup, runCleanroomClient, runCleanroomServer, universalJar, userdevJar, userdevSourcesJar, sourcesJar, javadocJar, installerJar, publishMmcPackZip
Userdev runClient, runServer, reobfJar
  • Run ./gradlew tasks --all for the complete pipeline.

Modifying Tooling

Tool configurations use defaults only while empty. Add a dependency to replace a tool without changing task wiring:

dependencies {
    decompiler 'example:replacement-decompiler:1.0'
    mergetool 'example:replacement-merger:1.0'
    accesstransformer 'example:replacement-at:1.0'
    installertools 'example:replacement-installer-tools:1.0'
}

If the replacement has a different command line, configure the corresponding MavenJarExec task with useDefaultToolArguments = false, mainClass, and args. These overrides apply in every mode.

A published userdev artifact records its exact source-producing tool coordinates.

Diagnostics

./gradlew cleanroomInfo

The report shows the effective mode, Minecraft version, names source, cache paths, configured/default tool versions, intermediate policy, and whether the client JAR, server JAR, and asset index are ready for offline use.

It does not resolve or download tool artifacts.

Offline Usage

Before using userdev with --offline, resolve the userdev dependency online once.

For loader and vanilla work, run the relevant setup, download, or client task online once so the shared cache contains version_manifest_v2.json and the selected version's meta.json. downloadAssets --offline validates all indexed objects and reports missing/corrupt assets together with a repair command.

Configuration and task validation failures use Gradle's Problems API. IDEs and the generated build/reports/problems/problems-report.html receive structured problem IDs, details, locations, and suggested fixes.

Cache Behavior

Gradle build-cache and configuration-cache support are enabled by this project's defaults.

Expensive deterministic transforms including: decompilation, mappings, access transformation, SAS, and binpatch work declare cacheable inputs and outputs.

  • clean deletes the build directory and caches.localDirectory, but preserves shared Minecraft downloads.
  • cleanCleanroomSharedCache explicitly deletes the configured shared caches.directory.
  • caches.discardIntermediates when set to true deletes consumed project-local pipeline artifact, cacheable tasks can restore them later.
    • A file is deleted after the consumers that ran in this build have finished.

For shared CI reuse, configure a Gradle local or remote build cache in the consuming build's settings.gradle; CleanroomGradle does not choose credentials or a cache server for you.

Sources in Userdev

The dependency exposes one normal combined module. Cacheable artifact transforms remap and combine patched Minecraft with Cleanroom, rebuild the matching patched sources, and select client or server extra resources. Gradle module metadata carries ordinary compile, runtime, and platform dependencies. userdev/config.json spec 1 carries only artifact-owned pipeline inputs, paths, identities, hashes, tools, and launch metadata.

IDE import resolves the combined jar on its first sync. No generated local Maven repository, synthetic module version, module-copy task, or setup invocation is involved. Extra access transformers are transform inputs, so changing one invalidates the combined artifact in Gradle's transform cache. IDE source lookup uses the published -sources.jar, while Gradle consumers can still request the attributed sources variant directly.

About

Gradle plugin for Cleanroom development, and vanilla usage.

Resources

Contributing

Security policy

Stars

22 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages