Skip to content

§1. Getting started

Arno Dölinger edited this page Jun 30, 2026 · 4 revisions

This page takes you from an empty build to a stripped, platform-specific JAR.

1. Add JitPack

// settings.gradle.kts
dependencyResolutionManagement {
    repositories {
        maven("https://jitpack.io")
    }
}

2. Add dependencies

// build.gradle.kts
dependencies {
    // Annotation classes
    compileOnly("com.github.arnodoelinger.platformweaver:platformweaver-annotations:VERSION")

    // Compiler plugin
    "kotlinCompilerPluginClasspath"("com.github.arnodoelinger.platformweaver:platformweaver-plugin:VERSION")

    // Both platform APIs as compileOnly, so types inside annotated blocks resolve
    compileOnly("net.fabricmc:fabric-api:...")
    compileOnly("io.papermc.paper:paper-api:...")
}

3. Set the target platform

// build.gradle.kts
tasks.withType<KotlinCompile>().configureEach {
    compilerOptions.freeCompilerArgs.addAll(
        "-P", "plugin:io.github.arnodoelinger.platformweaver:platform=paper"
    )
}

The target value is any platform key — paper, fabric, neoforge, or a custom one. Declarations annotated for a different platform are stripped from this build.

4. Write

import io.github.arnodoelinger.platformweaver.FabricOnly
import io.github.arnodoelinger.platformweaver.PaperOnly

object WorldHelper {

    // No annotation? Compiled into every JAR
    fun packCoords(x: Int, y: Int, z: Int): Long =
        (x.toLong() shl 38) or (z.toLong() shl 12) or y.toLong()

    // Fabric only? Stripped from the Paper build
    @FabricOnly fun getLevel(server: MinecraftServer, key: String): ServerLevel? {
        val rl = Identifier.parse(key)
        return server.getLevel(ResourceKey.create(Registries.DIMENSION, rl))
    }

    // Paper only
    @PaperOnly fun getWorld(name: String): World? = Bukkit.getWorld(name)
}

Compile for Paper and the @FabricOnly block is gone:

javap -p build/libs/my-paper.jar 'com.something.WorldHelper'
# getWorld(...) <- Paper version only. The Fabric one never made it to bytecode.

Next steps

Clone this wiki locally