From 5664a968088024db0c07cf492a49d8b8a215035d Mon Sep 17 00:00:00 2001 From: Phillipp Glanz <6745190+TheMeinerLP@users.noreply.github.com> Date: Sun, 12 May 2024 11:59:05 +0200 Subject: [PATCH] Improve build logic --- build-logic/src/main/kotlin/extensions.kt | 22 +++++++++++++++++++++- build.gradle.kts | 10 ++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/build-logic/src/main/kotlin/extensions.kt b/build-logic/src/main/kotlin/extensions.kt index f21d5671..0c696da7 100644 --- a/build-logic/src/main/kotlin/extensions.kt +++ b/build-logic/src/main/kotlin/extensions.kt @@ -1,5 +1,25 @@ -import java.io.ByteArrayOutputStream import org.gradle.api.Project +import org.gradle.api.publish.PublishingExtension +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.get +import org.gradle.kotlin.dsl.named +import java.io.ByteArrayOutputStream + +fun Project.publishShadowJar() { + configurePublication { + artifact(tasks["shadowJar"]) + artifact(tasks["sourcesJar"]) + } +} + +private fun Project.configurePublication(configurer: MavenPublication.() -> Unit) { + extensions.configure { + publications.named("mavenJava") { + apply(configurer) + } + } +} fun Project.latestCommitHash(): String { return runGitCommand(listOf("rev-parse", "--short", "HEAD")) diff --git a/build.gradle.kts b/build.gradle.kts index 5a1f86f0..2ad3d0ea 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -135,22 +135,24 @@ java { } tasks { + named("jar") { + archiveClassifier.set("unshaded") + } compileJava { options.release.set(17) options.encoding = "UTF-8" } shadowJar { - archiveClassifier.set(null as String?) + archiveClassifier.set("") dependencies { relocate("com.cryptomorin.xseries", "$group.xseries") relocate("org.incendo.serverlib", "$group.serverlib") relocate("org.bstats", "$group.metrics") relocate("io.papermc.lib", "$group.paperlib") } - minimize() } - build { + named("build") { dependsOn(shadowJar) } @@ -201,7 +203,7 @@ if (!isRelease || isMainBranch) { // Only publish releases from the main branch versionNumber.set(suffixedVersion) versionName.set(suffixedVersion) changelog.set(changelogContent) - uploadFile.set(tasks.shadowJar as Any) + uploadFile.set(tasks.shadowJar.flatMap { it.archiveFile }) gameVersions.addAll(supportedMinecraftVersions) loaders.add("paper") loaders.add("bukkit")