From 35bdc99873f03bbb58151aa2c0225ad310b94ccb Mon Sep 17 00:00:00 2001 From: Christian Bergschneider Date: Fri, 3 Jan 2025 23:52:31 +0100 Subject: [PATCH] build: make available via maven repo --- .../src/main/kotlin/DistributionConfig.kt | 51 ++++++++++++------- platforms/minestom/build.gradle.kts | 4 ++ 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/buildSrc/src/main/kotlin/DistributionConfig.kt b/buildSrc/src/main/kotlin/DistributionConfig.kt index a31588a518..72a4146f63 100644 --- a/buildSrc/src/main/kotlin/DistributionConfig.kt +++ b/buildSrc/src/main/kotlin/DistributionConfig.kt @@ -4,9 +4,11 @@ import java.io.File import java.io.FileWriter import java.net.URL import java.nio.file.FileSystems +import java.nio.file.Path import org.gradle.api.DefaultTask import org.gradle.api.Project import org.gradle.api.plugins.BasePluginExtension +import org.gradle.jvm.tasks.Jar import org.gradle.kotlin.dsl.apply import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.extra @@ -19,6 +21,25 @@ import kotlin.io.path.createDirectories import kotlin.io.path.createFile import kotlin.io.path.exists +private fun Project.installAddonsInto(dest: Path) { + FileSystems.newFileSystem(dest, mapOf("create" to "false"), null).use { fs -> + forSubProjects(":common:addons") { + val jar = getJarTask() + + logger.info("Packaging addon ${jar.archiveFileName.get()} to $dest. size: ${jar.archiveFile.get().asFile.length() / 1024}KB") + + val boot = if (extra.has("bootstrap") && extra.get("bootstrap") as Boolean) "bootstrap/" else "" + val addonPath = fs.getPath("/addons/$boot${jar.archiveFileName.get()}") + + if (!addonPath.exists()) { + addonPath.parent.createDirectories() + addonPath.createFile() + jar.archiveFile.get().asFile.toPath().copyTo(addonPath, overwrite = true) + } + + } + } +} fun Project.configureDistribution() { apply(plugin = "com.gradleup.shadow") @@ -48,25 +69,17 @@ fun Project.configureDistribution() { doLast { // https://github.com/johnrengelman/shadow/issues/111 val dest = tasks.named("shadowJar").get().archiveFile.get().path - - - FileSystems.newFileSystem(dest, mapOf("create" to "false"), null).use { fs -> - forSubProjects(":common:addons") { - val jar = getJarTask() - - logger.info("Packaging addon ${jar.archiveFileName.get()} to $dest. size: ${jar.archiveFile.get().asFile.length() / 1024}KB") - - val boot = if (extra.has("bootstrap") && extra.get("bootstrap") as Boolean) "bootstrap/" else "" - val addonPath = fs.getPath("/addons/$boot${jar.archiveFileName.get()}") - - if (!addonPath.exists()) { - addonPath.parent.createDirectories() - addonPath.createFile() - jar.archiveFile.get().asFile.toPath().copyTo(addonPath, overwrite = true) - } - - } - } + installAddonsInto(dest) + } + } + + tasks.create("installAddonsIntoDefaultJar") { + group = "terra" + dependsOn(compileAddons) + + doLast { + val dest = tasks.named("jar").get().archiveFile.get().path + installAddonsInto(dest) } } diff --git a/platforms/minestom/build.gradle.kts b/platforms/minestom/build.gradle.kts index b1fb58dfd2..b0732811ca 100644 --- a/platforms/minestom/build.gradle.kts +++ b/platforms/minestom/build.gradle.kts @@ -26,6 +26,10 @@ application { mainClass.set(javaMainClass) } +tasks.named("jar") { + finalizedBy("installAddonsIntoDefaultJar") +} + tasks.getByName("run").setProperty("workingDir", file("./run")) addonDir(project.file("./run/terra/addons"), tasks.named("run").get())