118 lines
5.4 KiB
Kotlin
118 lines
5.4 KiB
Kotlin
// ------------------------------ 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.
|
|
}
|
|
|
|
// --------------------------- 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.
|
|
}
|
|
}
|
|
|
|
// ----------------------------- Metadata ------------------------------
|
|
group = "me.eccentric_nz.gamemodeinventories" // Declare bundle identifier.
|
|
|
|
version = "3.5.1" // Declare plugin version (will be in .jar).
|
|
|
|
val apiVersion = "1.19" // Declare minecraft server target version.
|
|
|
|
// ----------------------------- Resources -----------------------------
|
|
tasks.named<ProcessResources>("processResources") {
|
|
val props = mapOf("version" to project.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("https://hub.spigotmc.org/nexus/content/groups/public/")
|
|
maven { url = uri("https://maven.playpro.com/") }
|
|
maven { url = uri("https://maven.enginehub.org/repo/") }
|
|
}
|
|
|
|
// ---------------------- 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.coreprotect:coreprotect:22.4") // Import the CoreProtect API.
|
|
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.9") // Import the WorldGuard API.
|
|
compileOnly(project(":libs:MyWorlds")) // Import MyWorlds API (git submodule, built from source).
|
|
compileOnly("com.bergerkiller.bukkit:BKCommonLib:1.19.4-v2") // Import BKCommonLib API from its Maven repository.
|
|
implementation("com.zaxxer:HikariCP:5.0.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.
|
|
}
|
|
|
|
// ---------------------- Reproducible jars ----------------------------
|
|
tasks.withType<AbstractArchiveTask>().configureEach { // Ensure reproducible .jars
|
|
isPreserveFileTimestamps = false
|
|
isReproducibleFileOrder = true
|
|
}
|
|
|
|
// ----------------------------- Shadow --------------------------------
|
|
tasks.shadowJar {
|
|
archiveClassifier.set("") // Use empty string instead of null.
|
|
exclude("io.github.miniplaceholders.*") // Exclude the MiniPlaceholders package from being shadowed.
|
|
exclude("org/purpurmc/**", "org/spigotmc/**")
|
|
isEnableRelocation = true
|
|
relocationPrefix = "${project.group}.shadow"
|
|
minimize {
|
|
// SLF4J discovers providers through META-INF/services, so Shadow's static minimizer cannot see this usage.
|
|
exclude(dependency("org.slf4j:slf4j-nop:.*"))
|
|
}
|
|
// relocate("com.zaxxer.hikari", "${project.group}.shadow.hikari")
|
|
mergeServiceFiles()
|
|
}
|
|
|
|
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.
|
|
}
|