Files

194 lines
9.2 KiB
Kotlin

/* This is free and unencumbered software released into the public domain */
/* ------------------------------ 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.
id("checkstyle") // Import Checkstyle plugin.
eclipse // Import Eclipse plugin.
kotlin("jvm") version "2.1.21" // Import Kotlin JVM plugin.
id("io.freefair.lombok") version "8.13.1" // Import automatic lombok support.
}
// Kotlin libraries consumed from source select their Kotlin variant through this attribute, like Template-OG.
extra["kotlinAttribute"] = Attribute.of("kotlin-tag", Boolean::class.javaObjectType)
val kotlinAttribute: Attribute<Boolean> by rootProject.extra
/* --------------------------- 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 ------------------------------ */
group = "uk.hotten.herobrine"
version = "1.6.3"
val apiVersion = "1.19" // Minecraft server target version.
val vendoredLicenseFiles =
fileTree("libs") {
include("**/LICENSE", "**/LICENSE.*", "**/License", "**/License.*", "**/COPYING", "**/COPYING.*")
include("**/NOTICE", "**/NOTICE.*")
exclude("**/build/**", "**/.git/**")
}
/* ----------------------------- Resources ----------------------------- */
tasks.named<ProcessResources>("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.
maven("https://ci.mg-dev.eu/plugin/repository/everything/") // BKCommonLib.
gradlePluginPortal() // Import the Gradle Plugin Portal Maven Repository.
maven { url = uri("https://repo.purpurmc.org/snapshots") } // Import the PurpurMC Maven Repository.
maven { url = uri("file://${System.getProperty("user.home")}/.m2/repository") }
System.getProperty("SELF_MAVEN_LOCAL_REPO")?.let { // TrueOG Bootstrap mavenLocal().
val dir = file(it)
if (dir.isDirectory) {
println("Using SELF_MAVEN_LOCAL_REPO at: $it")
maven { url = uri("file://${dir.absolutePath}") }
} else {
logger.error("TrueOG Bootstrap not found, defaulting to ~/.m2 for mavenLocal()")
mavenLocal()
}
} ?: logger.error("TrueOG Bootstrap not found, defaulting to ~/.m2 for mavenLocal()")
maven { url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") }
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") }
maven { url = uri("https://oss.sonatype.org/content/repositories/central") }
}
/* ---------------------- Java project deps ---------------------------- */
dependencies {
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.16.1")
implementation("com.fasterxml.jackson.core:jackson-databind:2.16.1")
implementation("commons-io:commons-io:2.11.0")
implementation("org.apache.commons:commons-pool2:2.11.1")
// SqlManager speaks jdbc:mariadb, so the MariaDB driver is the one that has to ship.
implementation("org.mariadb.jdbc:mariadb-java-client:3.3.3")
implementation("redis.clients:jedis:3.4.1")
implementation("org.slf4j:slf4j-api:2.0.17") // Bundle a relocated SLF4J API for shaded dependencies.
implementation("org.slf4j:slf4j-nop:2.0.17") // Provide a relocated no-op SLF4J backend to avoid provider warnings.
implementation("xyz.xenondevs:particle:1.8.3")
compileOnlyApi(project(":libs:Utilities-OG")) // Import TrueOG Network Utilities-OG Java API (from source).
compileOnly("org.purpurmc.purpur:purpur-api:1.19.4-R0.1-SNAPSHOT") // Declare Purpur API version to be packaged.
compileOnly("io.github.miniplaceholders:miniplaceholders-api:2.2.3") // Import MiniPlaceholders API.
compileOnly(
project(path = ":libs:ProtocolLib", configuration = "shadow")
) // Import TrueOG Network ProtocolLib fork (from source, its shaded jar).
compileOnly(project(":libs:IllegalStack-OG")) // Import TrueOG Network IllegalStack-OG Java API (from source).
compileOnly("com.bergerkiller.bukkit:BKCommonLib:1.19.4-v2") // Import BKCommonLib API from its Maven repository.
compileOnly(project(":libs:MyWorlds")) // Import MyWorlds API (git submodule, built from source).
compileOnly(
files("libs/Chat-OG/Chat-OG.jar")
) // Import Chat-OG API for world chat formatting (vendored jar until the API lands in trueog/Chat-OG).
compileOnly(project(":libs:Scoreboard-OG")) // Import TrueOG Network Scoreboard-OG Java API (from source).
implementation(project(":libs:GxUI-OG")) // Import TrueOG Network GxUI-OG Java API (from source).
implementation(
project(path = ":libs:ScoreboardLib", configuration = "shadow")
) // Import TrueOG Network ScoreboardLib fork (from source, its shaded jar).
}
/* ---------------------- Utility functions ---------------------------- */
tasks.register("updatePluginYmlVersion") {
doLast {
val file = file("src/main/resources/plugin.yml")
val lines = file.readLines().toMutableList()
lines[2] = "version: ${version}-trueog"
file.writeText(lines.joinToString("\n"))
}
}
fun revertPluginYmlVersion() {
val file = file("src/main/resources/plugin.yml")
val lines = file.readLines().toMutableList()
lines[2] = "version: $version"
file.writeText(lines.joinToString("\n"))
}
/* ---------------------- Reproducible jars ---------------------------- */
tasks.withType<AbstractArchiveTask>().configureEach { // Ensure reproducible .jars
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}
/* ----------------------------- Shadow -------------------------------- */
tasks.shadowJar {
exclude("io.github.miniplaceholders.*") // Exclude the MiniPlaceholders package from being shadowed.
from("LICENSE") {
into("META-INF/licenses/TheHerobrine-OG")
includeEmptyDirs = false
}
from(vendoredLicenseFiles) {
into("META-INF/licenses/libs")
includeEmptyDirs = false
}
// Every shaded dependency is relocated so Bukkit's cross-plugin class lookup can never hand
// this copy of jackson, jedis or the JDBC driver to another plugin, or the reverse.
isEnableRelocation = true
relocationPrefix = "${project.group}.shadow"
// The driver registers itself through META-INF/services, which relocation has to rewrite too.
mergeServiceFiles()
archiveClassifier.set("") // Use empty string instead of null.
minimize {
// The driver loads its authentication and TLS plugins reflectively, so keep it whole.
exclude(dependency("org.mariadb.jdbc:mariadb-java-client:.*"))
// SLF4J discovers providers through META-INF/services, so Shadow's static minimizer cannot see this usage.
exclude(dependency("org.slf4j:slf4j-nop:.*"))
}
}
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<JavaCompile>().configureEach {
options.compilerArgs.add("-parameters") // Enable reflection for java code.
options.isFork = true // Run javac in its own process.
options.compilerArgs.add("-Xlint:deprecation") // Trigger deprecation warning messages.
options.encoding = "UTF-8" // Use UTF-8 file encoding.
}
/* ----------------------------- Auto Formatting ------------------------ */
spotless {
java {
eclipse().configFile("config/formatter/eclipse-java-formatter.xml") // Eclipse java formatting.
leadingTabsToSpaces() // Convert leftover leading tabs to spaces.
removeUnusedImports() // Remove imports that aren't being called.
}
kotlinGradle {
ktfmt().kotlinlangStyle().configure { it.setMaxWidth(120) } // JetBrains Kotlin formatting.
target("build.gradle.kts", "settings.gradle.kts") // Gradle files to format.
}
}
checkstyle {
toolVersion = "10.18.1" // Declare checkstyle version to use.
configFile = file("config/checkstyle/checkstyle.xml") // Point checkstyle to config file.
isIgnoreFailures = true // Don't fail the build if checkstyle does not pass.
isShowViolations = true // Show the violations in any IDE with the checkstyle plugin.
}
tasks.named("compileJava") {
dependsOn("spotlessApply") // Run spotless before compiling with the JDK.
}
tasks.named("spotlessCheck") {
dependsOn("spotlessApply") // Run spotless before checking if spotless ran.
}