From 6b16bbc785152140fdf612b67aaacf0bf39e9e03 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Tue, 1 Jul 2025 19:00:14 +0200 Subject: [PATCH 1/5] Add DiscordDependency plugin for faster upload times --- .../DiscordDependency/build.gradle.kts | 36 +++++++++++++++++++ .../src/de/steamwar/discord/Discord.java | 29 +++++++++++++++ VelocityCore/build.gradle.kts | 5 +-- .../steamwar/velocitycore/VelocityCore.java | 2 +- settings.gradle.kts | 1 + steamwarci.yml | 1 + 6 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 VelocityCore/DiscordDependency/build.gradle.kts create mode 100644 VelocityCore/DiscordDependency/src/de/steamwar/discord/Discord.java diff --git a/VelocityCore/DiscordDependency/build.gradle.kts b/VelocityCore/DiscordDependency/build.gradle.kts new file mode 100644 index 00000000..5c4c27a6 --- /dev/null +++ b/VelocityCore/DiscordDependency/build.gradle.kts @@ -0,0 +1,36 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +plugins { + steamwar.java +} + +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} + +dependencies { + compileOnly(libs.velocity) + annotationProcessor(libs.velocityapi) + + implementation(libs.jda) { + exclude(module = "opus-java") + } +} \ No newline at end of file diff --git a/VelocityCore/DiscordDependency/src/de/steamwar/discord/Discord.java b/VelocityCore/DiscordDependency/src/de/steamwar/discord/Discord.java new file mode 100644 index 00000000..e4548697 --- /dev/null +++ b/VelocityCore/DiscordDependency/src/de/steamwar/discord/Discord.java @@ -0,0 +1,29 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.discord; + +import com.velocitypowered.api.plugin.Plugin; + +@Plugin( + id = "discordvelocitycore", + name = "DiscordVelocityCore" +) +public class Discord { +} diff --git a/VelocityCore/build.gradle.kts b/VelocityCore/build.gradle.kts index f81416a3..54b55e9c 100644 --- a/VelocityCore/build.gradle.kts +++ b/VelocityCore/build.gradle.kts @@ -51,6 +51,7 @@ dependencies { compileOnly(libs.viavelocity) compileOnly(project(":VelocityCore:Persistent", "default")) + compileOnly(project(":VelocityCore:DiscordDependency", "default")) implementation(project(":CommonCore")) implementation(project(":CommandFramework")) @@ -58,10 +59,6 @@ dependencies { implementation(libs.sqlite) implementation(libs.mysql) - implementation(libs.jda) { - exclude(module = "opus-java") - } - implementation(libs.msgpack) implementation(libs.apolloprotos) diff --git a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java index 392478b0..22b64f64 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java +++ b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java @@ -60,7 +60,7 @@ import java.util.logging.Logger; @Plugin( id = "velocitycore", name = "VelocityCore", - dependencies = { @Dependency(id = "persistentvelocitycore") } + dependencies = { @Dependency(id = "persistentvelocitycore"), @Dependency(id = "discordvelocitycore") } ) public class VelocityCore implements ReloadablePlugin { diff --git a/settings.gradle.kts b/settings.gradle.kts index 9b530499..cb175882 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -247,6 +247,7 @@ include("TutorialSystem") include( "VelocityCore", + "VelocityCore:DiscordDependency", "VelocityCore:Persistent" ) diff --git a/steamwarci.yml b/steamwarci.yml index 3e3660b1..d62f6b62 100644 --- a/steamwarci.yml +++ b/steamwarci.yml @@ -29,6 +29,7 @@ artifacts: "/jars/TutorialSystem.jar": "TutorialSystem/build/libs/TutorialSystem.jar" "/jars/PersistentVelocityCore.jar": "VelocityCore/Persistent/build/libs/Persistent.jar" + "/jars/DiscordVelocityCore.jar": "VelocityCore/DiscordDependency/build/libs/DiscordDependency.jar" "/jars/VelocityCore.jar": "VelocityCore/build/libs/VelocityCore-all.jar" "/usr/local/bin/deployarena.py": "VelocityCore/deployarena.py" From 8677d59cce95a99613c609b3f307ff0cbc60804a Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Tue, 1 Jul 2025 19:04:13 +0200 Subject: [PATCH 2/5] Fix some stuff --- VelocityCore/DiscordDependency/build.gradle.kts | 1 + VelocityCore/build.gradle.kts | 1 + 2 files changed, 2 insertions(+) diff --git a/VelocityCore/DiscordDependency/build.gradle.kts b/VelocityCore/DiscordDependency/build.gradle.kts index 5c4c27a6..dbe2ac56 100644 --- a/VelocityCore/DiscordDependency/build.gradle.kts +++ b/VelocityCore/DiscordDependency/build.gradle.kts @@ -19,6 +19,7 @@ plugins { steamwar.java + alias(libs.plugins.shadow) } java { diff --git a/VelocityCore/build.gradle.kts b/VelocityCore/build.gradle.kts index 54b55e9c..5074c280 100644 --- a/VelocityCore/build.gradle.kts +++ b/VelocityCore/build.gradle.kts @@ -70,5 +70,6 @@ tasks.register("DevVelocity") { description = "Run a Dev Velocity" dependsOn(":VelocityCore:shadowJar") dependsOn(":VelocityCore:Persistent:jar") + dependsOn(":VelocityCore:DiscordDependency:jar") template = "DevVelocity" } From 6efbda669e79d569c084db0e5e47566b8fdefbda Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 2 Jul 2025 11:17:55 +0200 Subject: [PATCH 3/5] Optimize and improve VelocityCore size Improve steamwar.devserver.gradle to not upload anything that is up to date! --- .../build.gradle.kts | 12 ++++++++++ .../de/steamwar/discord/Dependencies.java} | 6 ++--- VelocityCore/build.gradle.kts | 12 ++-------- .../steamwar/velocitycore/VelocityCore.java | 2 +- buildSrc/src/steamwar.devserver.gradle | 23 ++++++++++++++++--- settings.gradle.kts | 2 +- 6 files changed, 39 insertions(+), 18 deletions(-) rename VelocityCore/{DiscordDependency => Dependencies}/build.gradle.kts (83%) rename VelocityCore/{DiscordDependency/src/de/steamwar/discord/Discord.java => Dependencies/src/de/steamwar/discord/Dependencies.java} (88%) diff --git a/VelocityCore/DiscordDependency/build.gradle.kts b/VelocityCore/Dependencies/build.gradle.kts similarity index 83% rename from VelocityCore/DiscordDependency/build.gradle.kts rename to VelocityCore/Dependencies/build.gradle.kts index dbe2ac56..d71a6c10 100644 --- a/VelocityCore/DiscordDependency/build.gradle.kts +++ b/VelocityCore/Dependencies/build.gradle.kts @@ -22,6 +22,10 @@ plugins { alias(libs.plugins.shadow) } +tasks.build { + finalizedBy(tasks.shadowJar) +} + java { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 @@ -34,4 +38,12 @@ dependencies { implementation(libs.jda) { exclude(module = "opus-java") } + + implementation(libs.sqlite) + implementation(libs.mysql) + + implementation(libs.msgpack) + implementation(libs.apolloprotos) + + implementation(libs.nbt) } \ No newline at end of file diff --git a/VelocityCore/DiscordDependency/src/de/steamwar/discord/Discord.java b/VelocityCore/Dependencies/src/de/steamwar/discord/Dependencies.java similarity index 88% rename from VelocityCore/DiscordDependency/src/de/steamwar/discord/Discord.java rename to VelocityCore/Dependencies/src/de/steamwar/discord/Dependencies.java index e4548697..f3b2a243 100644 --- a/VelocityCore/DiscordDependency/src/de/steamwar/discord/Discord.java +++ b/VelocityCore/Dependencies/src/de/steamwar/discord/Dependencies.java @@ -22,8 +22,8 @@ package de.steamwar.discord; import com.velocitypowered.api.plugin.Plugin; @Plugin( - id = "discordvelocitycore", - name = "DiscordVelocityCore" + id = "depencendiesvelocitycore", + name = "DepencendiesVelocityCore" ) -public class Discord { +public class Dependencies { } diff --git a/VelocityCore/build.gradle.kts b/VelocityCore/build.gradle.kts index 5074c280..91121ea3 100644 --- a/VelocityCore/build.gradle.kts +++ b/VelocityCore/build.gradle.kts @@ -51,18 +51,10 @@ dependencies { compileOnly(libs.viavelocity) compileOnly(project(":VelocityCore:Persistent", "default")) - compileOnly(project(":VelocityCore:DiscordDependency", "default")) + compileOnly(project(":VelocityCore:Dependencies", "default")) implementation(project(":CommonCore")) implementation(project(":CommandFramework")) - - implementation(libs.sqlite) - implementation(libs.mysql) - - implementation(libs.msgpack) - implementation(libs.apolloprotos) - - implementation(libs.nbt) } tasks.register("DevVelocity") { @@ -70,6 +62,6 @@ tasks.register("DevVelocity") { description = "Run a Dev Velocity" dependsOn(":VelocityCore:shadowJar") dependsOn(":VelocityCore:Persistent:jar") - dependsOn(":VelocityCore:DiscordDependency:jar") + dependsOn(":VelocityCore:Dependencies:shadowJar") template = "DevVelocity" } diff --git a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java index 22b64f64..aa98a034 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java +++ b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java @@ -60,7 +60,7 @@ import java.util.logging.Logger; @Plugin( id = "velocitycore", name = "VelocityCore", - dependencies = { @Dependency(id = "persistentvelocitycore"), @Dependency(id = "discordvelocitycore") } + dependencies = { @Dependency(id = "persistentvelocitycore"), @Dependency(id = "depencendiesvelocitycore") } ) public class VelocityCore implements ReloadablePlugin { diff --git a/buildSrc/src/steamwar.devserver.gradle b/buildSrc/src/steamwar.devserver.gradle index 53f8be3d..5d75c087 100644 --- a/buildSrc/src/steamwar.devserver.gradle +++ b/buildSrc/src/steamwar.devserver.gradle @@ -46,6 +46,19 @@ class DevServer extends DefaultTask { DevServer() { super() + List upToDateTasks = [] + project.gradle.taskGraph.addTaskExecutionListener(new TaskExecutionListener() { + @Override + void beforeExecute(Task task) { + } + + @Override + void afterExecute(Task task, TaskState state) { + if (state.upToDate) { + upToDateTasks.add(task); + } + } + }) doFirst { List projects = [] projects.add(project) @@ -70,7 +83,7 @@ class DevServer extends DefaultTask { } doLast { checkHasTemplate() - uploadDependencies() + uploadDependencies(upToDateTasks) startDevServer() } finalizedBy(new Finalizer()) @@ -107,7 +120,7 @@ class DevServer extends DefaultTask { } } - void uploadDependencies() { + void uploadDependencies(List upToDateTasks) { def base = plugins == null ? "$template/plugins" : plugins println("Uploading to ~/$base") this.dependsOn.forEach { @@ -119,8 +132,12 @@ class DevServer extends DefaultTask { } else { throw new GradleException("Illegal argument for uploading dependencies") } - def archive = archiveTask.archiveFile.get().asFile + if (upToDateTasks.contains(archiveTask)) { + println("Skipping $archive") + return + } + println("Uploading $archive") new ProcessBuilder("ssh", host, "-T", "rm $base/${archive.name.replace("-all", "")}").start().waitFor() new ProcessBuilder("scp", archive.absolutePath, "$host:~/$base/${archive.name.replace("-all", "")}").start().waitFor() diff --git a/settings.gradle.kts b/settings.gradle.kts index cb175882..8ab618ff 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -247,7 +247,7 @@ include("TutorialSystem") include( "VelocityCore", - "VelocityCore:DiscordDependency", + "VelocityCore:Dependencies", "VelocityCore:Persistent" ) From 3b67048b9c1424452cf9d50de08c0eeeeb2a5e9b Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 2 Jul 2025 11:22:36 +0200 Subject: [PATCH 4/5] Improve jar size --- VelocityCore/Dependencies/build.gradle.kts | 12 ++++++++++++ VelocityCore/build.gradle.kts | 13 ------------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/VelocityCore/Dependencies/build.gradle.kts b/VelocityCore/Dependencies/build.gradle.kts index d71a6c10..009768d0 100644 --- a/VelocityCore/Dependencies/build.gradle.kts +++ b/VelocityCore/Dependencies/build.gradle.kts @@ -22,6 +22,18 @@ plugins { alias(libs.plugins.shadow) } +tasks.shadowJar { + exclude("META-INF/*") + exclude("org/sqlite/native/FreeBSD/**', 'org/sqlite/native/Mac/**', 'org/sqlite/native/Windows/**', 'org/sqlite/native/Linux-Android/**', 'org/sqlite/native/Linux-Musl/**") + exclude("org/sqlite/native/Linux/aarch64/**', 'org/sqlite/native/Linux/arm/**', 'org/sqlite/native/Linux/armv6/**', 'org/sqlite/native/Linux/armv7/**', 'org/sqlite/native/Linux/ppc64/**', 'org/sqlite/native/Linux/x86/**") + exclude("org/slf4j/**") + //https://imperceptiblethoughts.com/shadow/configuration/minimizing/ + minimize { + exclude(dependency("mysql:mysql-connector-java:.*")) + } + duplicatesStrategy = DuplicatesStrategy.INCLUDE +} + tasks.build { finalizedBy(tasks.shadowJar) } diff --git a/VelocityCore/build.gradle.kts b/VelocityCore/build.gradle.kts index 91121ea3..f290ed22 100644 --- a/VelocityCore/build.gradle.kts +++ b/VelocityCore/build.gradle.kts @@ -22,19 +22,6 @@ plugins { alias(libs.plugins.shadow) } -tasks.shadowJar { - exclude("META-INF/*") - exclude("org/sqlite/native/FreeBSD/**', 'org/sqlite/native/Mac/**', 'org/sqlite/native/Windows/**', 'org/sqlite/native/Linux-Android/**', 'org/sqlite/native/Linux-Musl/**") - exclude("org/sqlite/native/Linux/aarch64/**', 'org/sqlite/native/Linux/arm/**', 'org/sqlite/native/Linux/armv6/**', 'org/sqlite/native/Linux/armv7/**', 'org/sqlite/native/Linux/ppc64/**', 'org/sqlite/native/Linux/x86/**") - exclude("org/slf4j/**") - //https://imperceptiblethoughts.com/shadow/configuration/minimizing/ - minimize { - exclude(project(":VelocityCore")) - exclude(dependency("mysql:mysql-connector-java:.*")) - } - duplicatesStrategy = DuplicatesStrategy.INCLUDE -} - tasks.build { finalizedBy(tasks.shadowJar) } From e56c41ca6617b7cf1031527d3c41503b1cc8835a Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 2 Jul 2025 11:36:06 +0200 Subject: [PATCH 5/5] Improve dependency upload --- buildSrc/src/steamwar.devserver.gradle | 33 +++++++++++++------------- steamwarci.yml | 2 +- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/buildSrc/src/steamwar.devserver.gradle b/buildSrc/src/steamwar.devserver.gradle index 5d75c087..3c5cf882 100644 --- a/buildSrc/src/steamwar.devserver.gradle +++ b/buildSrc/src/steamwar.devserver.gradle @@ -1,3 +1,5 @@ +import java.security.MessageDigest + /* * This file is a part of the SteamWar software. * @@ -46,19 +48,6 @@ class DevServer extends DefaultTask { DevServer() { super() - List upToDateTasks = [] - project.gradle.taskGraph.addTaskExecutionListener(new TaskExecutionListener() { - @Override - void beforeExecute(Task task) { - } - - @Override - void afterExecute(Task task, TaskState state) { - if (state.upToDate) { - upToDateTasks.add(task); - } - } - }) doFirst { List projects = [] projects.add(project) @@ -83,7 +72,7 @@ class DevServer extends DefaultTask { } doLast { checkHasTemplate() - uploadDependencies(upToDateTasks) + uploadDependencies() startDevServer() } finalizedBy(new Finalizer()) @@ -120,7 +109,7 @@ class DevServer extends DefaultTask { } } - void uploadDependencies(List upToDateTasks) { + void uploadDependencies() { def base = plugins == null ? "$template/plugins" : plugins println("Uploading to ~/$base") this.dependsOn.forEach { @@ -132,8 +121,20 @@ class DevServer extends DefaultTask { } else { throw new GradleException("Illegal argument for uploading dependencies") } + def archive = archiveTask.archiveFile.get().asFile - if (upToDateTasks.contains(archiveTask)) { + + Process process = new ProcessBuilder("ssh", host, "-T", "sha1sum $base/${archive.name.replace("-all", "")}").start(); + byte[] bytes = MessageDigest.getInstance("sha1").digest(archive.bytes) + StringBuilder sb = new StringBuilder() + for (byte b : bytes) { + sb.append(String.format("%02X", b)) + } + boolean same = false + process.inputStream.readLines().forEach { + same |= it.startsWith(sb.toString().toLowerCase()) + } + if (same) { println("Skipping $archive") return } diff --git a/steamwarci.yml b/steamwarci.yml index d62f6b62..5548033a 100644 --- a/steamwarci.yml +++ b/steamwarci.yml @@ -29,7 +29,7 @@ artifacts: "/jars/TutorialSystem.jar": "TutorialSystem/build/libs/TutorialSystem.jar" "/jars/PersistentVelocityCore.jar": "VelocityCore/Persistent/build/libs/Persistent.jar" - "/jars/DiscordVelocityCore.jar": "VelocityCore/DiscordDependency/build/libs/DiscordDependency.jar" + "/jars/DependenciesVelocityCore.jar": "VelocityCore/Dependencies/build/libs/Dependencies-all.jar" "/jars/VelocityCore.jar": "VelocityCore/build/libs/VelocityCore-all.jar" "/usr/local/bin/deployarena.py": "VelocityCore/deployarena.py"