BlueMap/BlueMapCore/build.gradle.kts

140 lines
3.7 KiB
Plaintext
Raw Normal View History

import java.util.Properties
2022-07-26 22:04:01 +02:00
import java.io.IOException
plugins {
java
`java-library`
id("com.diffplug.spotless") version "6.1.2"
}
2022-07-26 22:04:01 +02:00
fun String.runCommand(): String = ProcessBuilder(split("\\s(?=(?:[^'\"`]*(['\"`])[^'\"`]*\\1)*[^'\"`]*$)".toRegex()))
.directory(projectDir)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start()
.apply { waitFor(60, TimeUnit.SECONDS) }
.run {
val error = errorStream.bufferedReader().readText().trim()
if (error.isNotEmpty()) {
throw IOException(error)
}
inputStream.bufferedReader().readText().trim()
}
val gitHash = "git rev-parse --verify HEAD".runCommand()
val clean = "git status --porcelain".runCommand().isEmpty()
2022-07-27 12:30:11 +02:00
val branch = "git rev-parse --abbrev-ref HEAD".runCommand()
val commitCount = "git rev-list --count HEAD".runCommand()
2022-07-27 12:30:11 +02:00
if (branch.isEmpty()) {
throw IllegalStateException("Could not determine branch name")
}
2022-07-26 22:04:01 +02:00
println("Git hash: $gitHash" + if (clean) "" else " (dirty)")
2022-07-27 12:30:11 +02:00
println("Branch: $branch")
val releaseProperties = Properties()
releaseProperties.load(file("../release.properties").inputStream())
group = "de.bluecolored.bluemap.core"
version = releaseProperties["version"].toString() + ".$commitCount" +
2022-07-27 12:30:11 +02:00
(if (clean) "" else ".dirty") +
(if (branch == "master") "" else "-$branch")
println("Version: $version")
2022-01-16 14:20:27 +01:00
val javaTarget = 11
java {
sourceCompatibility = JavaVersion.toVersion(javaTarget)
targetCompatibility = JavaVersion.toVersion(javaTarget)
}
repositories {
mavenCentral()
maven {
setUrl("https://jitpack.io")
}
}
@Suppress("GradlePackageUpdate")
dependencies {
api ("com.github.ben-manes.caffeine:caffeine:2.8.5")
api ("org.apache.commons:commons-lang3:3.6")
api ("commons-io:commons-io:2.5")
api ("org.spongepowered:configurate-hocon:4.1.1")
api ("org.spongepowered:configurate-gson:4.1.1")
api ("com.github.Querz:NBT:4.0")
api ("org.apache.commons:commons-dbcp2:2.9.0")
2022-07-24 12:10:00 +02:00
api ("de.bluecolored.bluemap.api:BlueMapAPI")
compileOnly ("org.jetbrains:annotations:23.0.0")
testImplementation ("org.junit.jupiter:junit-jupiter:5.8.2")
testRuntimeOnly ("org.junit.jupiter:junit-jupiter-engine:5.8.2")
}
spotless {
java {
target ("src/*/java/**/*.java")
licenseHeaderFile("../HEADER")
indentWithSpaces()
trimTrailingWhitespace()
}
}
tasks.withType(JavaCompile::class).configureEach {
options.apply {
encoding = "utf-8"
}
}
tasks.withType(AbstractArchiveTask::class).configureEach {
isReproducibleFileOrder = true
isPreserveFileTimestamps = false
}
tasks.test {
useJUnitPlatform()
}
tasks.processResources {
from("src/main/resources") {
include("de/bluecolored/bluemap/version.json")
duplicatesStrategy = DuplicatesStrategy.INCLUDE
expand (
"version" to project.version,
2022-07-26 22:04:01 +02:00
"gitHash" to gitHash + if (clean) "" else " (dirty)",
)
}
}
//resource Extensions
val resourceIds: Array<String> = arrayOf(
"1_13", "1_15", "1_16", "1_18"
)
tasks.register("zipResourceExtensions") {
resourceIds.forEach {
dependsOn("zipResourceExtensions$it")
}
}
resourceIds.forEach {
zipResourcesTask(it)
}
fun zipResourcesTask(resourceId: String) {
tasks.register ("zipResourceExtensions$resourceId", type = Zip::class) {
from(fileTree("src/main/resourceExtensions/mc$resourceId"))
archiveFileName.set("resourceExtensions.zip")
destinationDirectory.set(file("src/main/resources/de/bluecolored/bluemap/mc$resourceId/"))
outputs.upToDateWhen{ false }
}
}
//always update the zip before build
tasks.processResources {
dependsOn("zipResourceExtensions")
}