From be53cbf5bd8245efb335abdc86a1b7c77ccb132e Mon Sep 17 00:00:00 2001 From: alexcrea <42614139+alexcrea@users.noreply.github.com> Date: Wed, 16 Oct 2024 15:53:54 +0200 Subject: [PATCH] Better build script and create offline build --- build.gradle.kts | 74 ++++++++++++++++++++++++++++++----- src/main/resources/plugin.yml | 5 +-- 2 files changed, 66 insertions(+), 13 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 807e2df..cc8b5bb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,5 @@ import cn.lalaki.pub.BaseCentralPortalPlusExtension +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import org.jetbrains.kotlin.gradle.dsl.JvmTarget plugins { @@ -14,7 +15,7 @@ plugins { } group = "xyz.alexcrea" -version = "1.6.3" +version = "1.6.3-test" repositories { // EcoEnchants @@ -56,6 +57,9 @@ dependencies { implementation(project(":nms:v1_20R3", configuration = "reobf")) implementation(project(":nms:v1_20R4", configuration = "reobf")) implementation(project(":nms:v1_21R1", configuration = "reobf")) + + // include kotlin for the offline jar + implementation(kotlin("stdlib")) } allprojects { @@ -112,21 +116,66 @@ val fatJar = tasks.register("fatJar") { manifest { attributes.apply { put("Main-Class", "io.delilaheve.CustomAnvil") } } - archiveFileName.set("${rootProject.name}-${archiveVersion}.jar") + archiveFileName.set("${rootProject.name}-${project.version}.jar") exclude("META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA") duplicatesStrategy = DuplicatesStrategy.WARN from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) }) with(tasks.jar.get() as CopySpec) } -// Ensure fatJar and copyJar are run -tasks.getByName("build") { - dependsOn(fatJar) -} +tasks { + // Online jar (use of libraries) + shadowJar { + // No suffix for this jar + archiveClassifier.set("") + + // Exclude kotlin std and its annotation + exclude("**/kotlin-stdlib*.jar") + exclude("**/annotations*.jar") + + // Shadow necessary dependency + relocate("com.github.stefvanschie.inventoryframework", "xyz.alexcrea.inventoryframework") + + // Replace version and example fields in plugin.yml + filesMatching("plugin.yml") { + expand( + "version" to project.version, + "libraries" to " \"org.jetbrains.kotlin:kotlin-stdlib:1.9.24\" " + ) + } + + // Process resource for plugin.yml + dependsOn(processResources) + } + + // Offline jar (include kotlin std in the final jar fine) + val offlineJar by creating(ShadowJar::class) { + archiveClassifier.set("offline") + + // Shadow necessary dependency + relocate("com.github.stefvanschie.inventoryframework", "xyz.alexcrea.inventoryframework") + + filesMatching("plugin.yml") { + expand( + "version" to "${project.version}-offline", + "libraries" to "" + ) + } + + // Include all project other dependencies + from(project.configurations.runtimeClasspath) + + // Add custom anvil compiled + from(sourceSets.main.get().output) + + dependsOn(processResources) + } + + // Make the online and offline jar on build + named("build") { + dependsOn(shadowJar, offlineJar) + } -// Shadow necessary dependency -tasks.shadowJar { - relocate("com.github.stefvanschie.inventoryframework", "xyz.alexcrea.inventoryframework") } val sourcesJar by tasks.registering(Jar::class) { @@ -152,7 +201,12 @@ signing { // PUBLISHING TO SONATYPE CONFIGURATION // ------------------------------------ -val localMavenRepo = uri("E:\\WorkSpace\\Java\\Maven\\repo") // The path is recommended to be set to an empty directory +// The path is recommended to be set to an empty directory +val localMavenRepo = uri( + project.findProperty("localMavenRepo") as String? + ?: rootProject.layout.buildDirectory.dir("local-maven-repo").get().asFile.toURI() // Convert to URI +) + centralPortalPlus { url = localMavenRepo username = System.getenv("SONATYPE_USERNAME") diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index cea596d..4c27d82 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,14 +1,13 @@ main: io.delilaheve.CustomAnvil name: CustomAnvil prefix: "Custom Anvil" -version: 1.6.3 +version: ${version} folia-supported: true description: Allow to customise anvil mechanics api-version: 1.16 load: POSTWORLD authors: [ DelilahEve, alexcrea ] -libraries: - - org.jetbrains.kotlin:kotlin-stdlib:1.9.24 +libraries: [${libraries}] commands: anvilconfigreload: