3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 00:00:28 +01:00

Improve Gradle scripts

Don't create runnable platform jars anymore, since all they really do is increase build time. Also fix texts and Gradle deprecations. Also also publish common with its shadowed configuration, not the plain java components.
Dieser Commit ist enthalten in:
Nassim Jahnke 2023-11-06 13:11:35 +10:00
Ursprung 0474810b8d
Commit e356a35aa7
20 geänderte Dateien mit 51 neuen und 110 gelöschten Zeilen

Datei anzeigen

@ -1,7 +1,6 @@
plugins { plugins {
id("net.kyori.blossom") id("net.kyori.blossom")
id("org.jetbrains.gradle.plugin.idea-ext") id("org.jetbrains.gradle.plugin.idea-ext")
id("via.shadow-conventions")
} }
sourceSets { sourceSets {

Datei anzeigen

@ -61,7 +61,9 @@ public class StringType extends Type<String> {
@Override @Override
public void write(ByteBuf buffer, String object) throws Exception { public void write(ByteBuf buffer, String object) throws Exception {
Preconditions.checkArgument(object.length() <= maxLength, "Cannot send string longer than Short.MAX_VALUE (got %s characters)", object.length()); if (object.length() > maxLength) {
throw new IllegalArgumentException("Cannot send string longer than Short.MAX_VALUE characters (got " + object.length() + " characters)");
}
byte[] b = object.getBytes(StandardCharsets.UTF_8); byte[] b = object.getBytes(StandardCharsets.UTF_8);
Type.VAR_INT.writePrimitive(buffer, b.length); Type.VAR_INT.writePrimitive(buffer, b.length);

Datei anzeigen

@ -30,27 +30,21 @@ private fun Project.configurePublication(configurer: MavenPublication.() -> Unit
} }
fun Project.latestCommitHash(): String { fun Project.latestCommitHash(): String {
val byteOut = ByteArrayOutputStream() return runGitCommand(listOf("rev-parse", "--short", "HEAD"))
exec {
commandLine = listOf("git", "rev-parse", "--short", "HEAD")
standardOutput = byteOut
}
return byteOut.toString(Charsets.UTF_8.name()).trim()
} }
fun Project.latestCommitMessage(): String { fun Project.latestCommitMessage(): String {
val byteOut = ByteArrayOutputStream() return runGitCommand(listOf("log", "-1", "--pretty=%B"))
exec {
commandLine = listOf("git", "log", "-1", "--pretty=%B")
standardOutput = byteOut
}
return byteOut.toString(Charsets.UTF_8.name()).trim()
} }
fun Project.branchName(): String { fun Project.branchName(): String {
return runGitCommand(listOf("rev-parse", "--abbrev-ref", "HEAD"))
}
fun Project.runGitCommand(args: List<String>): String {
val byteOut = ByteArrayOutputStream() val byteOut = ByteArrayOutputStream()
exec { exec {
commandLine = listOf("git", "rev-parse", "--abbrev-ref", "HEAD") commandLine = listOf("git") + args
standardOutput = byteOut standardOutput = byteOut
} }
return byteOut.toString(Charsets.UTF_8.name()).trim() return byteOut.toString(Charsets.UTF_8.name()).trim()

Datei anzeigen

@ -15,10 +15,12 @@ tasks {
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:none", "-quiet") (options as StandardJavadocDocletOptions).addStringOption("Xdoclint:none", "-quiet")
} }
compileJava { compileJava {
//options.release.set(8)
options.encoding = Charsets.UTF_8.name() options.encoding = Charsets.UTF_8.name()
options.compilerArgs.addAll(listOf("-nowarn", "-Xlint:-unchecked", "-Xlint:-deprecation")) options.compilerArgs.addAll(listOf("-nowarn", "-Xlint:-unchecked", "-Xlint:-deprecation"))
} }
test {
useJUnitPlatform()
}
} }
java { java {

Datei anzeigen

@ -1,12 +0,0 @@
import java.util.*
plugins {
id("via.shadow-conventions")
}
tasks {
shadowJar {
archiveFileName.set("ViaVersion-${project.name.substringAfter("viaversion-").replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}-${project.version}.jar")
destinationDirectory.set(rootProject.layout.buildDirectory.dir("libs"))
}
}

Datei anzeigen

@ -1,5 +1,3 @@
import org.gradle.api.plugins.JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME
plugins { plugins {
base base
id("via.build-logic") id("via.build-logic")
@ -11,7 +9,10 @@ allprojects {
description = "Allow newer clients to join older server versions." description = "Allow newer clients to join older server versions."
} }
val platforms = setOf( val main = setOf(
projects.viaversion,
projects.viaversionCommon,
projects.viaversionApi,
projects.viaversionBukkit, projects.viaversionBukkit,
projects.viaversionBungee, projects.viaversionBungee,
projects.viaversionFabric, projects.viaversionFabric,
@ -20,23 +21,13 @@ val platforms = setOf(
).map { it.dependencyProject } ).map { it.dependencyProject }
val special = setOf( val special = setOf(
projects.viaversion,
projects.viaversionApi,
projects.adventure projects.adventure
).map { it.dependencyProject } ).map { it.dependencyProject }
subprojects { subprojects {
when (this) { when (this) {
in platforms -> plugins.apply("via.platform-conventions") in main -> plugins.apply("via.shadow-conventions")
in special -> plugins.apply("via.base-conventions") in special -> plugins.apply("via.base-conventions")
else -> plugins.apply("via.standard-conventions") else -> plugins.apply("via.standard-conventions")
} }
// Note: If manually starting tests doesn't work for you in IJ, change 'Gradle -> Run Tests Using' to 'IntelliJ IDEA'
dependencies {
// The alternative to this long boi is writing "testImplementation", including the quotes
TEST_IMPLEMENTATION_CONFIGURATION_NAME(rootProject.libs.netty)
TEST_IMPLEMENTATION_CONFIGURATION_NAME(rootProject.libs.guava)
TEST_IMPLEMENTATION_CONFIGURATION_NAME(rootProject.libs.bundles.junit)
}
} }

Datei anzeigen

@ -1,5 +1,5 @@
dependencies { dependencies {
implementation(projects.viaversionCommon) compileOnlyApi(projects.viaversionCommon)
compileOnly(libs.legacyBukkit) { compileOnly(libs.legacyBukkit) {
exclude("junit", "junit") exclude("junit", "junit")
exclude("com.google.code.gson", "gson") exclude("com.google.code.gson", "gson")

Datei anzeigen

@ -1,6 +1,6 @@
dependencies { dependencies {
implementation(projects.viaversionBukkitLegacy) implementation(projects.viaversionBukkitLegacy)
implementation(projects.viaversionCommon) compileOnlyApi(projects.viaversionCommon)
compileOnly(libs.paper) { compileOnly(libs.paper) {
exclude("junit", "junit") exclude("junit", "junit")
exclude("com.google.code.gson", "gson") exclude("com.google.code.gson", "gson")

Datei anzeigen

@ -72,7 +72,7 @@ public final class ProtocolSupportCompat {
} catch (NoSuchMethodException ignored) { } catch (NoSuchMethodException ignored) {
} }
// Check for obfusacted b/c methods // Check for obfuscated b/c methods
try { try {
if (clazz.getMethod("b").getReturnType() == int.class) { if (clazz.getMethod("b").getReturnType() == int.class) {
return HandshakeProtocolType.OBFUSCATED_B; return HandshakeProtocolType.OBFUSCATED_B;

Datei anzeigen

@ -1,4 +1,4 @@
dependencies { dependencies {
implementation(projects.viaversionCommon) compileOnlyApi(projects.viaversionCommon)
compileOnly(libs.bungee) compileOnly(libs.bungee)
} }

Datei anzeigen

@ -3,6 +3,12 @@ dependencies {
api(projects.viaversionApiLegacy) api(projects.viaversionApiLegacy)
implementation(projects.compat.snakeyaml2Compat) implementation(projects.compat.snakeyaml2Compat)
implementation(projects.compat.snakeyaml1Compat) implementation(projects.compat.snakeyaml1Compat)
// Note: If manually starting tests doesn't work for you in IJ, change 'Gradle -> Run Tests Using' to 'IntelliJ IDEA'
testImplementation(rootProject.libs.netty)
testImplementation(rootProject.libs.guava)
testImplementation(rootProject.libs.snakeYaml2)
testImplementation(rootProject.libs.bundles.junit)
} }
java { java {

Datei anzeigen

@ -32,9 +32,10 @@ public class ProtocolVersionTest {
@Test @Test
void testVersionRange() { void testVersionRange() {
Assertions.assertEquals(ProtocolVersion.v1_7_1, ProtocolVersion.getClosest("1.7")); Assertions.assertEquals(ProtocolVersion.v1_20, ProtocolVersion.getClosest("1.20"));
Assertions.assertEquals(ProtocolVersion.v1_7_1, ProtocolVersion.getClosest("1.7.0")); Assertions.assertEquals(ProtocolVersion.v1_20, ProtocolVersion.getClosest("1.20.0"));
Assertions.assertEquals(ProtocolVersion.v1_7_1, ProtocolVersion.getClosest("1.7.1")); Assertions.assertEquals(ProtocolVersion.v1_20, ProtocolVersion.getClosest("1.20.1"));
Assertions.assertEquals(ProtocolVersion.v1_7_1, ProtocolVersion.getClosest("1.7.2"));
Assertions.assertEquals(ProtocolVersion.v1_7_1, ProtocolVersion.getClosest("1.7.5")); Assertions.assertEquals(ProtocolVersion.v1_7_1, ProtocolVersion.getClosest("1.7.5"));
} }

Datei anzeigen

@ -38,7 +38,7 @@ public class ItemTypeTest {
// Test item read // Test item read
Assertions.assertEquals( Assertions.assertEquals(
new DataItem((int) Short.MAX_VALUE, (byte) -128, (short) 257, null), new DataItem(Short.MAX_VALUE, (byte) -128, (short) 257, null),
Type.ITEM1_8.read(Unpooled.wrappedBuffer(new byte[]{ Type.ITEM1_8.read(Unpooled.wrappedBuffer(new byte[]{
127, -1, 127, -1,
-128, -128,
@ -83,7 +83,7 @@ public class ItemTypeTest {
ByteBuf buf = Unpooled.buffer(); ByteBuf buf = Unpooled.buffer();
// Test item write // Test item write
Type.ITEM1_8.write(buf, new DataItem((int) Short.MAX_VALUE, (byte) -128, (short) 257, null)); Type.ITEM1_8.write(buf, new DataItem(Short.MAX_VALUE, (byte) -128, (short) 257, null));
Assertions.assertArrayEquals(toBytes(buf), new byte[]{ Assertions.assertArrayEquals(toBytes(buf), new byte[]{
127, -1, 127, -1,
-128, -128,

Datei anzeigen

@ -23,7 +23,6 @@ import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
public class StringTypeTest { public class StringTypeTest {
@Test @Test
@ -41,45 +40,29 @@ public class StringTypeTest {
Type.STRING.write(buf, new String(new char[Short.MAX_VALUE])); Type.STRING.write(buf, new String(new char[Short.MAX_VALUE]));
Assertions.assertEquals(Type.STRING.read(buf), new String(new char[Short.MAX_VALUE])); Assertions.assertEquals(Type.STRING.read(buf), new String(new char[Short.MAX_VALUE]));
Type.STRING.write(buf, new String(new char[Short.MAX_VALUE]).replace("\0", "ç")); Type.STRING.write(buf, new String(new char[Short.MAX_VALUE]).replace("\0", "a"));
Assertions.assertEquals(Type.STRING.read(buf), new String(new char[Short.MAX_VALUE]).replace("\0", "ç")); Assertions.assertEquals(Type.STRING.read(buf), new String(new char[Short.MAX_VALUE]).replace("\0", "a"));
Type.STRING.write(buf, new String(new char[Short.MAX_VALUE / 2]).replace("\0", "\uD83E\uDDFD")); Type.STRING.write(buf, new String(new char[Short.MAX_VALUE / 2]).replace("\0", "\uD83E\uDDFD"));
Assertions.assertEquals(Type.STRING.read(buf), new String(new char[Short.MAX_VALUE / 2]).replace("\0", "\uD83E\uDDFD")); Assertions.assertEquals(Type.STRING.read(buf), new String(new char[Short.MAX_VALUE / 2]).replace("\0", "\uD83E\uDDFD"));
} }
@Test @Test
public void testStringReadOverflowException() throws Exception { public void testStringReadOverflowException() {
// Read exception // Read exception
final ByteBuf buf = Unpooled.buffer(); final ByteBuf buf = Unpooled.buffer();
Type.VAR_INT.writePrimitive(buf, (Short.MAX_VALUE + 1) * 4); Type.VAR_INT.writePrimitive(buf, (Short.MAX_VALUE + 1) * 4);
for (int i = 0; i < Short.MAX_VALUE / 2 + 1; i++) { for (int i = 0; i < Short.MAX_VALUE / 2 + 1; i++) {
buf.writeBytes(new byte[]{0x04, (byte) 0xf0, (byte) 0x9f, (byte) 0xa7, (byte) 0xbd}); // Sponge emoji buf.writeBytes(new byte[]{0x04, (byte) 0xf0, (byte) 0x9f, (byte) 0xa7, (byte) 0xbd}); // Sponge emoji
} }
Assertions.assertThrows(IllegalArgumentException.class, new Executable() { Assertions.assertThrows(IllegalArgumentException.class, () -> Type.STRING.read(buf));
@Override
public void execute() throws Throwable {
Type.STRING.read(buf);
}
});
} }
@Test @Test
public void testStringWriteOverflowException() { public void testStringWriteOverflowException() {
// Write exceptions // Write exceptions
final ByteBuf buf = Unpooled.buffer(); final ByteBuf buf = Unpooled.buffer();
Assertions.assertThrows(IllegalArgumentException.class, new Executable() { Assertions.assertThrows(IllegalArgumentException.class, () -> Type.STRING.write(buf, new String(new char[Short.MAX_VALUE / 2 + 1]).replace("\0", "\uD83E\uDDFD")));
@Override Assertions.assertThrows(IllegalArgumentException.class, () -> Type.STRING.write(buf, new String(new char[Short.MAX_VALUE + 1])));
public void execute() throws Throwable {
Type.STRING.write(buf, new String(new char[Short.MAX_VALUE / 2 + 1]).replace("\0", "\uD83E\uDDFD"));
}
});
Assertions.assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() throws Throwable {
Type.STRING.write(buf, new String(new char[Short.MAX_VALUE + 1]));
}
});
} }
} }

Datei anzeigen

@ -1,3 +1,2 @@
dependencies { dependencies {
implementation(projects.viaversionCommon)
} }

Datei anzeigen

@ -22,7 +22,6 @@ paper = "1.16.5-R0.1-SNAPSHOT"
legacyBukkit = "1.8.8-R0.1-SNAPSHOT" legacyBukkit = "1.8.8-R0.1-SNAPSHOT"
bungee = "1.19-R0.1-SNAPSHOT" bungee = "1.19-R0.1-SNAPSHOT"
sponge = "8.0.0" sponge = "8.0.0"
legacySponge = "4.0.0"
velocity = "3.1.1" velocity = "3.1.1"
@ -52,7 +51,6 @@ paper = { group = "com.destroystokyo.paper", name = "paper-api", version.ref = "
legacyBukkit = { group = "org.bukkit", name = "bukkit", version.ref = "legacyBukkit" } legacyBukkit = { group = "org.bukkit", name = "bukkit", version.ref = "legacyBukkit" }
bungee = { group = "net.md-5", name = "bungeecord-api", version.ref = "bungee" } bungee = { group = "net.md-5", name = "bungeecord-api", version.ref = "bungee" }
sponge = { group = "org.spongepowered", name = "spongeapi", version.ref = "sponge" } sponge = { group = "org.spongepowered", name = "spongeapi", version.ref = "sponge" }
legacySponge = { group = "org.spongepowered", name = "spongeapi", version.ref = "legacySponge" }
velocity = { group = "com.velocitypowered", name = "velocity-api", version.ref = "velocity" } velocity = { group = "com.velocitypowered", name = "velocity-api", version.ref = "velocity" }

Datei anzeigen

@ -1,4 +1,4 @@
dependencies { dependencies {
implementation(projects.viaversionCommon) compileOnlyApi(projects.viaversionCommon)
compileOnly(libs.sponge) compileOnly(libs.sponge)
} }

Datei anzeigen

@ -1,3 +1,3 @@
dependencies { dependencies {
implementation(projects.viaversionCommon) compileOnly(projects.viaversionCommon)
} }

Datei anzeigen

@ -1,48 +1,26 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import io.papermc.hangarpublishplugin.model.Platforms import io.papermc.hangarpublishplugin.model.Platforms
plugins { plugins {
id("com.github.johnrengelman.shadow")
id("io.papermc.hangar-publish-plugin") version "0.1.0" id("io.papermc.hangar-publish-plugin") version "0.1.0"
id("com.modrinth.minotaur") version "2.+" id("com.modrinth.minotaur") version "2.+"
} }
val platforms = setOf( dependencies {
rootProject.projects.viaversionBukkit, api(projects.viaversionCommon)
rootProject.projects.viaversionBungee, api(projects.viaversionBukkit)
rootProject.projects.viaversionFabric, api(projects.viaversionBungee)
rootProject.projects.viaversionSponge, api(projects.viaversionFabric)
rootProject.projects.viaversionVelocity api(projects.viaversionSponge)
).map { it.dependencyProject } api(projects.viaversionVelocity)
}
tasks { tasks {
shadowJar { shadowJar {
archiveClassifier.set("")
archiveFileName.set("ViaVersion-${project.version}.jar") archiveFileName.set("ViaVersion-${project.version}.jar")
destinationDirectory.set(rootProject.projectDir.resolve("build/libs")) destinationDirectory.set(rootProject.projectDir.resolve("build/libs"))
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
platforms.forEach { platform ->
val shadowJarTask = platform.tasks.named<ShadowJar>("shadowJar").forUseAtConfigurationTime().get()
dependsOn(shadowJarTask)
dependsOn(platform.tasks.withType<Jar>())
from(zipTree(shadowJarTask.archiveFile))
}
}
build {
dependsOn(shadowJar)
}
sourcesJar {
rootProject.subprojects.forEach { subproject ->
if (subproject == project) return@forEach
val platformSourcesJarTask = subproject.tasks.findByName("sourcesJar") as? Jar ?: return@forEach
dependsOn(platformSourcesJarTask)
from(zipTree(platformSourcesJarTask.archiveFile))
}
} }
} }
publishShadowJar()
val branch = rootProject.branchName() val branch = rootProject.branchName()
val baseVersion = project.version as String val baseVersion = project.version as String
val isRelease = !baseVersion.contains('-') val isRelease = !baseVersion.contains('-')

Datei anzeigen

@ -1,5 +1,5 @@
dependencies { dependencies {
implementation(projects.viaversionCommon) compileOnlyApi(projects.viaversionCommon)
compileOnly(libs.velocity) { compileOnly(libs.velocity) {
// Requires Java 11 // Requires Java 11
exclude("com.velocitypowered", "velocity-brigadier") exclude("com.velocitypowered", "velocity-brigadier")