Skip to content

Commit

Permalink
Improve build logic
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMeinerLP committed May 12, 2024
1 parent 578a9d3 commit 5664a96
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
22 changes: 21 additions & 1 deletion build-logic/src/main/kotlin/extensions.kt
Original file line number Diff line number Diff line change
@@ -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<PublishingExtension> {
publications.named<MavenPublication>("mavenJava") {
apply(configurer)
}
}
}

fun Project.latestCommitHash(): String {
return runGitCommand(listOf("rev-parse", "--short", "HEAD"))
Expand Down
10 changes: 6 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,24 @@ java {
}

tasks {
named<Jar>("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)
}

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 5664a96

Please sign in to comment.