-
Notifications
You must be signed in to change notification settings - Fork 0
§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.
// settings.gradle.kts
dependencyResolutionManagement {
repositories {
maven("https://jitpack.io")
}
}// 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:...")
}// 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.
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.- See every annotation and how to define your own in Annotations.
- When the platforms differ only in a type or accessor, don't write the function twice — see Merging platforms with
@Chameleon.