3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 00:00:41 +01:00

Feature: JiJ dependencies on modded platforms (#4502)

* Use JiJ inclusion for Fabric/NeoForge to prevent mod conflicts. Further: Don't publish shadow jars to maven.

* Shade and relocate dependencies that don't conform to SemVer on Fabric

* Shade/Relocate dependencies on Fabric to avoid version warnings

* Use relocate function from the build-logic plugin
Dieser Commit ist enthalten in:
chris 2024-03-19 23:05:30 +01:00 committet von GitHub
Ursprung b03818a0c4
Commit 867cf6da05
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
10 geänderte Dateien mit 117 neuen und 60 gelöschten Zeilen

Datei anzeigen

@ -1,7 +1,7 @@
dependencies { dependencies {
api(projects.core) api(projects.core)
implementation(libs.adventure.text.serializer.bungeecord) implementation(libs.adventure.text.serializer.bungeecord)
compileOnlyApi(libs.bungeecord.proxy)
} }
platformRelocate("net.md_5.bungee.jni") platformRelocate("net.md_5.bungee.jni")

Datei anzeigen

@ -7,6 +7,8 @@ architectury {
fabric() fabric()
} }
val includeTransitive: Configuration = configurations.getByName("includeTransitive")
dependencies { dependencies {
modImplementation(libs.fabric.loader) modImplementation(libs.fabric.loader)
modApi(libs.fabric.api) modApi(libs.fabric.api)
@ -15,14 +17,29 @@ dependencies {
shadow(project(path = ":mod", configuration = "transformProductionFabric")) { shadow(project(path = ":mod", configuration = "transformProductionFabric")) {
isTransitive = false isTransitive = false
} }
shadow(projects.core) { shadow(projects.core) { isTransitive = false }
exclude(group = "com.google.guava", module = "guava") includeTransitive(projects.core)
exclude(group = "com.google.code.gson", module = "gson")
exclude(group = "org.slf4j")
exclude(group = "com.nukkitx.fastutil")
exclude(group = "io.netty.incubator")
}
// These are NOT transitively included, and instead shadowed + relocated.
// Avoids fabric complaining about non-SemVer versioning
// TODO: re-evaluate after loom 1.6 (https://github.com/FabricMC/fabric-loom/pull/1075)
shadow(libs.protocol.connection) { isTransitive = false }
shadow(libs.protocol.common) { isTransitive = false }
shadow(libs.protocol.codec) { isTransitive = false }
shadow(libs.mcauthlib) { isTransitive = false }
shadow(libs.raknet) { isTransitive = false }
shadow(libs.netty.codec.haproxy) { isTransitive = false }
shadow("org.cloudburstmc:nbt:3.0.2.Final") { isTransitive = false }
shadow("io.netty:netty-codec-dns:4.1.103.Final") { isTransitive = false }
shadow("io.netty:netty-resolver-dns-classes-macos:4.1.103.Final") { isTransitive = false }
// Consequences of shading + relocating mcauthlib: shadow/relocate mcpl!
shadow(libs.mcprotocollib) { isTransitive = false }
// Since we also relocate cloudburst protocol: shade erosion common
shadow(libs.erosion.common) { isTransitive = false }
// Permissions
modImplementation(libs.fabric.permissions) modImplementation(libs.fabric.permissions)
include(libs.fabric.permissions) include(libs.fabric.permissions)
} }
@ -31,6 +48,16 @@ application {
mainClass.set("org.geysermc.geyser.platform.fabric.GeyserFabricMain") mainClass.set("org.geysermc.geyser.platform.fabric.GeyserFabricMain")
} }
relocate("org.cloudburstmc.nbt")
relocate("org.cloudburstmc.netty")
relocate("org.cloudburstmc.protocol")
relocate("io.netty.handler.codec.dns")
relocate("io.netty.handler.codec.haproxy")
relocate("io.netty.resolver.dns.macos")
relocate("com.github.steveice10.mc.protocol")
relocate("com.github.steveice10.mc.auth")
relocate("com.github.steveice10.packetlib")
tasks { tasks {
remapJar { remapJar {
archiveBaseName.set("Geyser-Fabric") archiveBaseName.set("Geyser-Fabric")

Datei anzeigen

@ -2,11 +2,17 @@ plugins {
application application
} }
// This is provided by "org.cloudburstmc.math.mutable" too, so yeet.
// NeoForge's class loader is *really* annoying.
provided("org.cloudburstmc.math", "api")
architectury { architectury {
platformSetupLoomIde() platformSetupLoomIde()
neoForge() neoForge()
} }
val includeTransitive: Configuration = configurations.getByName("includeTransitive")
dependencies { dependencies {
// See https://github.com/google/guava/issues/6618 // See https://github.com/google/guava/issues/6618
modules { modules {
@ -21,12 +27,9 @@ dependencies {
shadow(project(path = ":mod", configuration = "transformProductionNeoForge")) { shadow(project(path = ":mod", configuration = "transformProductionNeoForge")) {
isTransitive = false isTransitive = false
} }
shadow(projects.core) { shadow(project(path = ":core")) { isTransitive = false }
exclude(group = "com.google.guava", module = "guava")
exclude(group = "com.google.code.gson", module = "gson") includeTransitive(projects.core)
exclude(group = "org.slf4j")
exclude(group = "io.netty.incubator")
}
} }
application { application {
@ -34,10 +37,6 @@ application {
} }
tasks { tasks {
shadowJar {
relocate("it.unimi.dsi.fastutil", "org.geysermc.relocate.fastutil")
}
remapJar { remapJar {
archiveBaseName.set("Geyser-NeoForge") archiveBaseName.set("Geyser-NeoForge")
} }

Datei anzeigen

@ -12,17 +12,10 @@ dependencies {
implementation(libs.adventure.text.serializer.bungeecord) implementation(libs.adventure.text.serializer.bungeecord)
// Both folia-api and paper-mojangapi only provide Java 17 versions for 1.19 compileOnly(libs.folia.api)
compileOnly(libs.folia.api) { compileOnly(libs.paper.mojangapi)
attributes {
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 17) compileOnlyApi(libs.viaversion)
}
}
compileOnly(libs.paper.mojangapi) {
attributes {
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 17)
}
}
} }
platformRelocate("it.unimi.dsi.fastutil") platformRelocate("it.unimi.dsi.fastutil")

Datei anzeigen

@ -1,6 +1,8 @@
dependencies { dependencies {
annotationProcessor(libs.velocity.api) annotationProcessor(libs.velocity.api)
api(projects.core) api(projects.core)
compileOnlyApi(libs.velocity.api)
} }
platformRelocate("com.fasterxml.jackson") platformRelocate("com.fasterxml.jackson")

Datei anzeigen

@ -1,5 +1,7 @@
dependencies { dependencies {
api(projects.core) api(projects.core)
compileOnlyApi(libs.viaproxy)
} }
platformRelocate("net.kyori") platformRelocate("net.kyori")

Datei anzeigen

@ -58,19 +58,20 @@ fun Project.platformRelocate(pattern: String, exclusion: String = "") {
val providedDependencies = mutableMapOf<String, MutableSet<String>>() val providedDependencies = mutableMapOf<String, MutableSet<String>>()
fun Project.provided(pattern: String, name: String, version: String, excludedOn: Int = 0b110) { fun getProvidedDependenciesForProject(projectName: String): MutableSet<String> {
return providedDependencies.getOrDefault(projectName, emptySet()).toMutableSet()
}
fun Project.provided(pattern: String, name: String, excludedOn: Int = 0b110) {
providedDependencies.getOrPut(project.name) { mutableSetOf() } providedDependencies.getOrPut(project.name) { mutableSetOf() }
.add("${calcExclusion(pattern, 0b100, excludedOn)}:" + .add("${calcExclusion(pattern, 0b100, excludedOn)}:${calcExclusion(name, 0b10, excludedOn)}")
"${calcExclusion(name, 0b10, excludedOn)}:" +
calcExclusion(version, 0b1, excludedOn))
dependencies.add("compileOnlyApi", "$pattern:$name:$version")
} }
fun Project.provided(dependency: ProjectDependency) = fun Project.provided(dependency: ProjectDependency) =
provided(dependency.group!!, dependency.name, dependency.version!!) provided(dependency.group!!, dependency.name)
fun Project.provided(dependency: MinimalExternalModuleDependency) = fun Project.provided(dependency: MinimalExternalModuleDependency) =
provided(dependency.module.group, dependency.module.name, dependency.versionConstraint.requiredVersion) provided(dependency.module.group, dependency.module.name)
fun Project.provided(provider: Provider<MinimalExternalModuleDependency>) = fun Project.provided(provider: Provider<MinimalExternalModuleDependency>) =
provided(provider.get()) provided(provider.get())

Datei anzeigen

@ -11,6 +11,31 @@ plugins {
id("com.modrinth.minotaur") id("com.modrinth.minotaur")
} }
// These are provided by Minecraft/modded platforms already, no need to include them
provided("com.google.code.gson", "gson")
provided("com.google.guava", ".*")
provided("org.slf4j", "slf4j-api")
provided("com.nukkitx.fastutil", ".*")
provided("org.cloudburstmc.fastutil.maps", ".*")
provided("org.cloudburstmc.fastutil.sets", ".*")
provided("org.cloudburstmc.fastutil.commons", ".*")
provided("org.cloudburstmc.fastutil", ".*")
provided("org.checkerframework", "checker-qual")
provided("io.netty", "netty-transport-classes-epoll")
provided("io.netty", "netty-transport-native-epoll")
provided("io.netty", "netty-transport-native-unix-common")
provided("io.netty", "netty-transport-classes-kqueue")
provided("io.netty", "netty-transport-native-kqueue")
provided("io.netty", "netty-handler")
provided("io.netty", "netty-common")
provided("io.netty", "netty-buffer")
provided("io.netty", "netty-resolver")
provided("io.netty", "netty-transport")
provided("io.netty", "netty-codec")
provided("io.netty", "netty-resolver-dns")
provided("io.netty", "netty-resolver-dns-native-macos")
provided("org.ow2.asm", "asm")
architectury { architectury {
minecraft = "1.20.4" minecraft = "1.20.4"
} }
@ -19,6 +44,10 @@ loom {
silentMojangMappingsLicense() silentMojangMappingsLicense()
} }
configurations {
create("includeTransitive").isTransitive = true
}
tasks { tasks {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present. // if it is present.
@ -34,28 +63,6 @@ tasks {
// The remapped shadowJar is the final desired mod jar // The remapped shadowJar is the final desired mod jar
archiveVersion.set(project.version.toString()) archiveVersion.set(project.version.toString())
archiveClassifier.set("shaded") archiveClassifier.set("shaded")
relocate("org.objectweb.asm", "org.geysermc.relocate.asm")
relocate("org.yaml", "org.geysermc.relocate.yaml") // https://github.com/CardboardPowered/cardboard/issues/139
relocate("com.fasterxml.jackson", "org.geysermc.relocate.jackson")
relocate("net.kyori", "org.geysermc.relocate.kyori")
dependencies {
// Exclude everything EXCEPT some DNS stuff required for HAProxy
exclude(dependency("io.netty:netty-transport-classes-epoll:.*"))
exclude(dependency("io.netty:netty-transport-native-epoll:.*"))
exclude(dependency("io.netty:netty-transport-native-unix-common:.*"))
exclude(dependency("io.netty:netty-transport-classes-kqueue:.*"))
exclude(dependency("io.netty:netty-transport-native-kqueue:.*"))
exclude(dependency("io.netty:netty-handler:.*"))
exclude(dependency("io.netty:netty-common:.*"))
exclude(dependency("io.netty:netty-buffer:.*"))
exclude(dependency("io.netty:netty-resolver:.*"))
exclude(dependency("io.netty:netty-transport:.*"))
exclude(dependency("io.netty:netty-codec:.*"))
exclude(dependency("io.netty:netty-resolver-dns:.*"))
exclude(dependency("io.netty:netty-resolver-dns-native-macos:.*"))
}
} }
remapJar { remapJar {
@ -73,6 +80,27 @@ tasks {
} }
} }
afterEvaluate {
val providedDependencies = getProvidedDependenciesForProject(project.name)
// These are shaded, no need to JiJ them
configurations["shadow"].dependencies.forEach {shadowed ->
println("Not including shadowed dependency: ${shadowed.group}:${shadowed.name}")
providedDependencies.add("${shadowed.group}:${shadowed.name}")
}
// Now: Include all transitive dependencies that aren't excluded
configurations["includeTransitive"].resolvedConfiguration.resolvedArtifacts.forEach { dep ->
if (!providedDependencies.contains("${dep.moduleVersion.id.group}:${dep.moduleVersion.id.name}")
and !providedDependencies.contains("${dep.moduleVersion.id.group}:.*")) {
println("Including dependency via JiJ: ${dep.id}")
dependencies.add("include", dep.moduleVersion.id.toString())
} else {
println("Not including ${dep.id} for ${project.name}!")
}
}
}
dependencies { dependencies {
minecraft("com.mojang:minecraft:1.20.4") minecraft("com.mojang:minecraft:1.20.4")
mappings(loom.officialMojangMappings()) mappings(loom.officialMojangMappings())

Datei anzeigen

@ -7,3 +7,9 @@ indra {
publishSnapshotsTo("geysermc", "https://repo.opencollab.dev/maven-snapshots") publishSnapshotsTo("geysermc", "https://repo.opencollab.dev/maven-snapshots")
publishReleasesTo("geysermc", "https://repo.opencollab.dev/maven-releases") publishReleasesTo("geysermc", "https://repo.opencollab.dev/maven-releases")
} }
publishing {
// skip shadow jar from publishing. Workaround for https://github.com/johnrengelman/shadow/issues/651
val javaComponent = project.components["java"] as AdhocComponentWithVariants
javaComponent.withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) { skip() }
}

Datei anzeigen

@ -7,7 +7,6 @@ plugins {
tasks { tasks {
named<Jar>("jar") { named<Jar>("jar") {
archiveClassifier.set("unshaded")
from(project.rootProject.file("LICENSE")) from(project.rootProject.file("LICENSE"))
} }
val shadowJar = named<ShadowJar>("shadowJar") { val shadowJar = named<ShadowJar>("shadowJar") {