Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12241795
build.gradle.kts
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
build.gradle.kts
View Options
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.Copy
import java.security.MessageDigest
import java.util.Properties
plugins {
id("java")
}
group = "org.eu.loupsgris.quilvaryn"
version = "0.1-SNAPSHOT"
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
repositories {
mavenCentral()
maven {
name = "papermc"
url = uri("https://repo.papermc.io/repository/maven-public/")
}
}
dependencies {
testImplementation(platform("org.junit:junit-bom:5.10.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
// Paper API (includes Bukkit + Spigot)
compileOnly("io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT")
// Adventure for l10n
compileOnly("net.kyori:adventure-api:4.24.0")
implementation("net.kyori:adventure-text-serializer-plain:4.24.0")
}
val promoteEnglishMessagesAsDefault by tasks.registering(Copy::class) {
from("src/main/resources/l10n/messages_en.properties")
into("src/main/resources/l10n")
rename { "messages.properties" }
}
tasks.processResources {
dependsOn(
promoteEnglishMessagesAsDefault,
)
}
tasks.named("build") {
dependsOn(
promoteEnglishMessagesAsDefault,
"updateResourcePackProperties",
)
}
val resourcePackSourceDir = layout.projectDirectory.dir("src/main/resources/resourcepack")
val resourcePackProperties = layout.projectDirectory.file("src/main/resources/resourcepack.properties")
val resourcePackBuildDir = layout.buildDirectory.dir("resourcepack")
val resourcePackZip = resourcePackBuildDir.get().file("suhayl.zip")
val resourcePackSha1 = resourcePackBuildDir.get().file("suhayl.sha1")
tasks.register<Zip>("zipResourcePack") {
from(resourcePackSourceDir)
archiveFileName.set("suhayl.zip")
destinationDirectory.set(resourcePackBuildDir)
}
tasks.register("computeResourcePackSha1") {
dependsOn("zipResourcePack")
inputs.file(resourcePackZip)
outputs.file(resourcePackSha1)
doLast {
val zipFile = resourcePackZip.asFile
val sha1 = MessageDigest.getInstance("SHA-1")
.digest(zipFile.readBytes())
.joinToString("") { "%02x".format(it) }
resourcePackSha1.asFile.writeText(sha1)
println("Resource pack SHA1: $sha1")
}
}
tasks.register("updateResourcePackProperties") {
dependsOn("computeResourcePackSha1")
doLast {
val sha1 = resourcePackSha1.asFile.readText().trim()
val propsFile = resourcePackProperties.asFile
val props = Properties().apply {
if (propsFile.exists()) {
propsFile.inputStream().use { load(it) }
}
}
props["resourcepack.url"] = "https://windriver.nasqueron.org/~minecraft/packs/suhayl.zip"
props["resourcepack.sha1"] = sha1
propsFile.outputStream().use { props.store(it, "Updated by Gradle") }
println("Updated ${propsFile.name} with SHA1=$sha1")
}
}
tasks.register<Exec>("deployResourcePack") {
val remoteHost = (findProperty("remoteHost") as String?) ?: "windriver.nasqueron.org"
val remoteUser = (findProperty("remoteUser") as String?) ?: System.getenv("USER") ?: "deploy"
val remoteDir = (findProperty("remoteResourcePackDir") as String?) ?: "/var/home-wwwroot/minecraft/packs/"
dependsOn("updateResourcePackProperties")
val zipFile = resourcePackZip.asFile
commandLine("scp", zipFile.absolutePath, "$remoteUser@$remoteHost:$remoteDir")
}
tasks.register("updateServerProperties") {
group = "deployment"
description = "Fetch server.properties, update resource-pack-sha1, and push back."
dependsOn(
"deployResourcePack",
"updateResourcePackProperties",
)
doLast {
val remoteHost = (findProperty("remoteHost") as String?) ?: "windriver.nasqueron.org"
val remoteUser = (findProperty("remoteUser") as String?) ?: System.getenv("USER") ?: "deploy"
val remotePath = (findProperty("remoteServerPropertiesPath") as String?) ?: "/usr/local/minecraft/server.properties"
val localFile = layout.buildDirectory.file("server.properties").get()
val localPath = localFile.asFile.absolutePath
// Read hash from properties generated during updateResourcePackProperties task
val properties = Properties().apply {
resourcePackProperties.asFile.inputStream().use { load(it) }
}
val sha1 = properties.getProperty("resourcepack.sha1")
?: throw GradleException("Missing property 'resource-pack-sha1' in ${resourcePackProperties.asFile}")
exec {
commandLine("scp", "$remoteUser@$remoteHost:$remotePath", localPath)
}
val propertiesFile = localFile.asFile;
val lines = propertiesFile.readLines().toMutableList()
val idx = lines.indexOfFirst { it.startsWith("resource-pack-sha1=") }
if (idx >= 0) {
lines[idx] = "resource-pack-sha1=$sha1"
} else {
lines.add("resource-pack-sha1=$sha1")
}
propertiesFile.writeText(lines.joinToString("\n"))
exec {
commandLine("scp", localPath, "$remoteUser@$remoteHost:$remotePath")
}
println("✅ Updated server.properties with resource-pack-sha1=$sha1")
}
}
tasks.register<Exec>("deploy") {
group = "deployment"
description = "SCP the built JAR to windriver.nasqueron.org (configurable via -PremoteUser and -PremoteDir)."
dependsOn(
tasks.named("build"),
tasks.named("jar"),
tasks.named("deployResourcePack"),
tasks.named("updateServerProperties"),
)
val remoteHost = (findProperty("remoteHost") as String?) ?: "windriver.nasqueron.org"
val remoteUser = (findProperty("remoteUser") as String?) ?: System.getenv("USER") ?: "deploy"
val remoteDir = (findProperty("remoteDir") as String?) ?: ""
// Resolve the jar file produced by the 'jar' task
val jarTask = tasks.named<Jar>("jar").get()
val jarFileProvider = jarTask.archiveFile
doFirst {
val jarFile = jarFileProvider.get().asFile
if (!jarFile.exists()) {
throw GradleException("JAR not found at ${'$'}{jarFile.absolutePath}. Try running './gradlew build' first.")
}
commandLine("scp", jarFile.absolutePath, "$remoteUser@$remoteHost:$remoteDir")
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Oct 12, 06:30 (1 d, 8 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3054654
Default Alt Text
build.gradle.kts (6 KB)
Attached To
Mode
rQVR Quilvaryn
Attached
Detach File
Event Timeline
Log In to Comment