Skip to content

Commit

Permalink
Fix lib relocation when lib is not included
Browse files Browse the repository at this point in the history
Alright, this basically occurred because the shared project used to relocate almost every library, for example, SnakeYaml was being relocated as YamlFile uses it and it's part of the shared project, but when using MCUtils-Spigot as a plugin, an exception was thrown as the relocated classes weren't present. This is because MCUtils-Spigot does not shade SnakeYaml as it is present on Spigot already. Sadly, now every platform has to relocate its libraries to fix this issue (Except jetbrains annotations, which are global and as such part of the mcutils shadow conventions)
  • Loading branch information
xDec0de committed Nov 3, 2024
1 parent cbd525b commit 55178d9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
30 changes: 15 additions & 15 deletions buildSrc/src/main/kotlin/mcutils.shadow-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import org.gradle.kotlin.dsl.support.uppercaseFirstChar

plugins {
java
com.gradleup.shadow
java
com.gradleup.shadow
}

tasks {
shadowJar {
archiveClassifier = null
shadowJar {
archiveFileName = "MCUtils-" + project.name.uppercaseFirstChar() + "-${rootProject.version}.jar"
archiveClassifier = null

relocate("org.jetbrains.annotations", "net.codersky.mcutils.shaded.jetbrains.annotations")
relocate("org.intellij.lang.annotations", "net.codersky.mcutils.shaded.intellij.annotations")
relocate("net.kyori", "net.codersky.mcutils.shaded.kyori")
relocate("org.yaml.snakeyaml", "net.codersky.mcutils.shaded.snakeyaml")
relocate("org.jetbrains.annotations", "net.codersky.mcutils.shaded.jetbrains.annotations")
relocate("org.intellij.lang.annotations", "net.codersky.mcutils.shaded.intellij.annotations")

mergeServiceFiles()
minimize()
}
mergeServiceFiles()
minimize()
}

assemble {
dependsOn(shadowJar)
}
assemble {
dependsOn(shadowJar)
}
}

configurations.implementation.get().extendsFrom(configurations.shadow.get())
configurations.implementation.get().extendsFrom(configurations.shadow.get())
5 changes: 5 additions & 0 deletions platforms/spigot/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ dependencies {
}

tasks {

shadowJar {
relocate("net.kyori", "net.codersky.mcutils.shaded.kyori")
}

// 1.8.8 - 1.16.5 = Java 8
// 1.17 = Java 16
// 1.18 - 1.20.4 = Java 17
Expand Down
7 changes: 7 additions & 0 deletions platforms/universal/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ dependencies {
api(libs.adventure.serializer.legacy)
api(libs.snakeyaml)
}

tasks {
shadowJar {
relocate("net.kyori", "net.codersky.mcutils.shaded.kyori")
relocate("org.yaml.snakeyaml", "net.codersky.mcutils.shaded.snakeyaml")
}
}
6 changes: 6 additions & 0 deletions platforms/velocity/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ dependencies {
implementation(libs.snakeyaml)
compileOnly(libs.velocity)
}

tasks {
shadowJar {
relocate("org.yaml.snakeyaml", "net.codersky.mcutils.shaded.snakeyaml")
}
}

0 comments on commit 55178d9

Please sign in to comment.