/* This is free and unencumbered software released into the public domain */ import java.io.BufferedReader /* ------------------------------ Plugins ------------------------------ */ plugins { id("java") // Import Java plugin. id("java-library") // Import Java Library plugin. id("com.diffplug.spotless") version "8.1.0" // Import Spotless plugin. id("com.gradleup.shadow") version "8.3.9" // Import Shadow plugin. eclipse // Import Eclipse plugin. kotlin("jvm") version "2.1.21" // Import Kotlin JVM plugin. } /* --------------------------- JDK / Kotlin ---------------------------- */ java { sourceCompatibility = JavaVersion.VERSION_17 // Compile with JDK 17 compatibility. toolchain { // Select Java toolchain. languageVersion.set(JavaLanguageVersion.of(17)) // Use JDK 17. vendor.set(JvmVendorSpec.GRAAL_VM) // Use GraalVM CE. } } kotlin { jvmToolchain(17) } /* ----------------------------- Metadata ------------------------------ */ val commitHash = Runtime.getRuntime().exec(arrayOf("git", "rev-parse", "--short=10", "HEAD")).let { process -> process.waitFor() val output = process.inputStream.use { it.bufferedReader().use(BufferedReader::readText) } process.destroy() output.trim() } group = "net.trueog" val apiVersion = "1.19" version = "$apiVersion-$commitHash" /* ----------------------------- Resources ----------------------------- */ tasks.named("processResources") { val props = mapOf("version" to version, "apiVersion" to apiVersion) inputs.properties(props) // Indicates to rerun if version changes. filesMatching("plugin.yml") { expand(props) } from("LICENSE") { into("/") } // Bundle licenses into jarfiles. } /* ---------------------------- Repos ---------------------------------- */ repositories { mavenCentral() // Import the Maven Central Maven Repository. gradlePluginPortal() // Import the Gradle Plugin Portal Maven Repository. maven { url = uri("https://repo.purpurmc.org/snapshots") } // Import the PurpurMC Maven Repository. maven { url = uri("https://repo.lucko.me/") } // Import the LuckPerms Maven Repository. } /* ---------------------- Java project deps ---------------------------- */ dependencies { compileOnly("org.purpurmc.purpur:purpur-api:1.19.4-R0.1-SNAPSHOT") // Declare Purpur API version to be packaged. compileOnly("net.luckperms:api:5.5") // Declare LuckPerms API for prefix/name color lookups. implementation("org.jetbrains.kotlin:kotlin-stdlib") // Import Kotlin standard library. implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2") // Import Kotlin async library. } /* ---------------------- Reproducible jars ---------------------------- */ tasks.withType().configureEach { // Ensure reproducible .jars isPreserveFileTimestamps = false isReproducibleFileOrder = true } /* ----------------------------- Shadow -------------------------------- */ tasks.shadowJar { exclude("io.github.miniplaceholders.*") // Exclude the MiniPlaceholders package from being shadowed. archiveClassifier.set("") // Use empty string instead of null. minimize() } tasks.jar { archiveClassifier.set("part") } // Applies to root jarfile only. tasks.build { dependsOn(tasks.spotlessApply, tasks.shadowJar) } // Build depends on spotless and shadow. /* --------------------------- Javac opts ------------------------------- */ tasks.withType().configureEach { options.compilerArgs.add("-Xlint:deprecation") // Trigger deprecation warning messages. options.encoding = "UTF-8" // Use UTF-8 file encoding. } /* ----------------------------- Auto Formatting ------------------------ */ spotless { kotlin { ktfmt().kotlinlangStyle().configure { it.setMaxWidth(120) } } kotlinGradle { ktfmt().kotlinlangStyle().configure { it.setMaxWidth(120) } // JetBrains Kotlin formatting. target("build.gradle.kts", "settings.gradle.kts") // Gradle files to format. } } tasks.named("spotlessCheck") { dependsOn("spotlessApply") // Run spotless before checking if spotless ran. }