plugins() {
  id("java")

  id("com.gradleup.shadow").version("8.3.6")

  id("checkstyle")
  id("com.github.spotbugs").version("6.1.7")
  id("org.cadixdev.licenser").version("0.6.1")

  id("com.github.gmazzo.buildconfig").version("4.1.2") // Kotlin :skull:
}

this.group = "net.elytrium"
this.version = "1.2.4"

compileJava() {
  sourceCompatibility = 17
  targetCompatibility = 17
  options.getRelease().set(17)

  options.setEncoding("UTF-8")
}

repositories() {
  mavenCentral()

  maven {
    name = "papermc-repo"
    url = "https://repo.papermc.io/repository/maven-public/"
  }
  maven {
    name = "elytrium-repo"
    url = "https://maven.elytrium.net/repo/"
  }
}

dependencies() {
  annotationProcessor("net.java.dev.jna:jna-platform:5.13.0")

  compileOnly("com.github.spotbugs:spotbugs-annotations:4.9.3")

  compileOnly("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT")
  annotationProcessor("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT")
  compileOnly("com.velocitypowered:velocity-proxy:3.4.0-SNAPSHOT") // From Elytrium Repo.

  // Needs for some velocity methods.
  compileOnly("io.netty:netty-transport:4.1.101.Final")
  compileOnly("it.unimi.dsi:fastutil-core:8.5.12")

  // To suppress VulnerableLibrariesLocal of velocity-api dependency.
  compileOnly("org.yaml:snakeyaml:2.2")

  implementation("net.elytrium.commons:kyori:1.3.0")
  implementation("net.elytrium.commons:velocity:1.3.0")
  implementation("net.elytrium.commons:utils:1.3.0")
  implementation("net.elytrium:serializer:1.1.1")
  implementation("net.elytrium:fastprepare:1.0.11")

  implementation("org.bstats:bstats-velocity:3.0.2")
}

shadowJar() {
  archiveClassifier = null

  minimize()
  enableRelocation = true
  relocationPrefix = "net.elytrium.velocitytools.3rdparty"
}

checkstyle() {
  toolVersion = "10.12.1"

  configFile = file(".config/checkstyle/checkstyle.xml")
  configProperties = ["configDirectory": "$rootDir/.config/checkstyle"]
  maxErrors = 0
  maxWarnings = 0
}

spotbugsMain() {
  reports.register("html") {
    required = true
    outputLocation.fileValue(file("${project.layout.buildDirectory.get()}/reports/spotbugs/main/spotbugs.html"))
    stylesheet = "fancy-hist.xsl"
  }
}

license() {
  header = file("HEADER.txt")

  exclude("**/BuildConfig.java")
}

buildConfig() {
  packageName("net.elytrium.velocitytools")
  buildConfigField("String", "VERSION", "\"$version\"")
}

assemble.dependsOn(shadowJar)
