2022-07-26 22:04:01 +02:00
|
|
|
import java.io.IOException
|
2022-12-13 16:54:31 +01:00
|
|
|
import java.util.concurrent.TimeoutException
|
2022-01-15 01:18:02 +01:00
|
|
|
|
|
|
|
plugins {
|
|
|
|
java
|
|
|
|
`java-library`
|
2022-12-04 00:18:45 +01:00
|
|
|
`maven-publish`
|
2022-01-15 01:18:02 +01:00
|
|
|
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()
|
2022-12-13 16:54:31 +01:00
|
|
|
.apply {
|
|
|
|
if (!waitFor(10, TimeUnit.SECONDS)) {
|
|
|
|
throw TimeoutException("Failed to execute command: '" + this@runCommand + "'")
|
|
|
|
}
|
|
|
|
}
|
2022-07-26 22:04:01 +02:00
|
|
|
.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()
|
2024-02-07 20:43:37 +01:00
|
|
|
var clean = false;
|
|
|
|
try {
|
|
|
|
clean = "git status --porcelain".runCommand().isEmpty();
|
|
|
|
} catch (ex: TimeoutException) {
|
|
|
|
println("Failed to run 'git status --porcelain', assuming dirty version.")
|
|
|
|
}
|
2023-05-19 12:14:31 +02:00
|
|
|
val lastTag = if ("git tag".runCommand().isEmpty()) "" else "git describe --tags --abbrev=0".runCommand()
|
|
|
|
val lastVersion = if (lastTag.isEmpty()) "dev" else lastTag.substring(1) // remove the leading 'v'
|
2022-07-27 15:10:23 +02:00
|
|
|
val commits = "git rev-list --count $lastTag..HEAD".runCommand()
|
2022-07-26 22:04:01 +02:00
|
|
|
println("Git hash: $gitHash" + if (clean) "" else " (dirty)")
|
2022-01-15 01:18:02 +01:00
|
|
|
|
2024-04-04 02:07:09 +02:00
|
|
|
group = "de.bluecolored.bluemap"
|
2024-06-18 01:40:42 +02:00
|
|
|
version = lastVersion +
|
|
|
|
(if (commits == "0") "" else "-$commits") +
|
|
|
|
(if (clean) "" else "-dirty")
|
2022-07-27 15:10:23 +02:00
|
|
|
|
|
|
|
System.setProperty("bluemap.version", version.toString())
|
2024-04-04 02:07:09 +02:00
|
|
|
System.setProperty("bluemap.lastVersion", lastVersion)
|
2022-07-27 11:39:22 +02:00
|
|
|
println("Version: $version")
|
2022-01-15 01:18:02 +01:00
|
|
|
|
2024-03-29 13:08:59 +01:00
|
|
|
val javaTarget = 16
|
2022-01-15 01:18:02 +01:00
|
|
|
java {
|
|
|
|
sourceCompatibility = JavaVersion.toVersion(javaTarget)
|
|
|
|
targetCompatibility = JavaVersion.toVersion(javaTarget)
|
2024-06-17 23:48:31 +02:00
|
|
|
withSourcesJar()
|
2024-06-18 01:40:42 +02:00
|
|
|
withJavadocJar()
|
2022-01-15 01:18:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
repositories {
|
|
|
|
mavenCentral()
|
2024-04-04 02:07:09 +02:00
|
|
|
maven ("https://repo.bluecolored.de/releases")
|
2022-01-15 01:18:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Suppress("GradlePackageUpdate")
|
|
|
|
dependencies {
|
2024-05-12 20:11:31 +02:00
|
|
|
api ("com.github.ben-manes.caffeine:caffeine:3.1.8")
|
2022-10-10 18:00:03 +02:00
|
|
|
api ("org.spongepowered:configurate-hocon:4.1.2")
|
|
|
|
api ("org.spongepowered:configurate-gson:4.1.2")
|
2024-05-07 16:45:24 +02:00
|
|
|
api ("de.bluecolored.bluenbt:BlueNBT:2.3.0")
|
2022-01-15 01:18:02 +01:00
|
|
|
api ("org.apache.commons:commons-dbcp2:2.9.0")
|
2023-05-09 22:52:29 +02:00
|
|
|
api ("io.airlift:aircompressor:0.24")
|
2024-02-07 20:43:37 +01:00
|
|
|
api ("org.lz4:lz4-java:1.8.0")
|
2022-01-15 01:18:02 +01:00
|
|
|
|
2024-04-04 02:07:09 +02:00
|
|
|
api ("de.bluecolored.bluemap:BlueMapAPI")
|
2022-07-24 12:10:00 +02:00
|
|
|
|
|
|
|
compileOnly ("org.jetbrains:annotations:23.0.0")
|
2024-05-12 20:11:31 +02:00
|
|
|
compileOnly ("org.projectlombok:lombok:1.18.32")
|
2024-02-07 20:43:37 +01:00
|
|
|
|
2024-05-12 20:11:31 +02:00
|
|
|
annotationProcessor ("org.projectlombok:lombok:1.18.32")
|
2022-05-28 21:55:41 +02:00
|
|
|
|
2022-01-15 01:18:02 +01:00
|
|
|
testImplementation ("org.junit.jupiter:junit-jupiter:5.8.2")
|
|
|
|
testRuntimeOnly ("org.junit.jupiter:junit-jupiter-engine:5.8.2")
|
2024-05-12 20:11:31 +02:00
|
|
|
testCompileOnly ("org.projectlombok:lombok:1.18.32")
|
|
|
|
testAnnotationProcessor ("org.projectlombok:lombok:1.18.32")
|
2022-01-15 01:18:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
spotless {
|
|
|
|
java {
|
|
|
|
target ("src/*/java/**/*.java")
|
|
|
|
|
|
|
|
licenseHeaderFile("../HEADER")
|
|
|
|
indentWithSpaces()
|
|
|
|
trimTrailingWhitespace()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-18 01:40:42 +02:00
|
|
|
tasks.javadoc {
|
|
|
|
options {
|
|
|
|
(this as? StandardJavadocDocletOptions)?.apply {
|
|
|
|
links(
|
|
|
|
"https://docs.oracle.com/en/java/javase/16/docs/api/",
|
|
|
|
"https://javadoc.io/doc/com.flowpowered/flow-math/1.0.3/",
|
|
|
|
"https://javadoc.io/doc/com.google.code.gson/gson/2.8.0/",
|
|
|
|
)
|
|
|
|
addStringOption("Xdoclint:none", "-quiet")
|
|
|
|
addBooleanOption("html5", true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-15 01:18:02 +01:00
|
|
|
tasks.withType(JavaCompile::class).configureEach {
|
|
|
|
options.apply {
|
|
|
|
encoding = "utf-8"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.withType(AbstractArchiveTask::class).configureEach {
|
|
|
|
isReproducibleFileOrder = true
|
|
|
|
isPreserveFileTimestamps = false
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.test {
|
|
|
|
useJUnitPlatform()
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.processResources {
|
2022-07-30 16:07:10 +02:00
|
|
|
outputs.upToDateWhen { false }
|
2022-01-15 01:18:02 +01:00
|
|
|
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)",
|
2022-01-15 01:18:02 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-08 19:31:36 +02:00
|
|
|
tasks.register("zipResourceExtensions", type = Zip::class) {
|
|
|
|
from(fileTree("src/main/resourceExtensions"))
|
|
|
|
archiveFileName.set("resourceExtensions.zip")
|
|
|
|
destinationDirectory.set(file("src/main/resources/de/bluecolored/bluemap/"))
|
|
|
|
outputs.upToDateWhen{ false }
|
2022-01-15 01:18:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//always update the zip before build
|
2024-06-17 23:48:31 +02:00
|
|
|
tasks.processResources { dependsOn("zipResourceExtensions") }
|
|
|
|
tasks.getByName("sourcesJar") { dependsOn("zipResourceExtensions") }
|
2022-12-04 00:18:45 +01:00
|
|
|
|
|
|
|
publishing {
|
2024-04-04 02:07:09 +02:00
|
|
|
repositories {
|
|
|
|
maven {
|
|
|
|
name = "bluecolored"
|
|
|
|
|
|
|
|
val releasesRepoUrl = "https://repo.bluecolored.de/releases"
|
|
|
|
val snapshotsRepoUrl = "https://repo.bluecolored.de/snapshots"
|
|
|
|
url = uri(if (version == lastVersion) releasesRepoUrl else snapshotsRepoUrl)
|
|
|
|
|
|
|
|
credentials {
|
|
|
|
username = project.findProperty("bluecoloredUsername") as String? ?: System.getenv("BLUECOLORED_USERNAME")
|
|
|
|
password = project.findProperty("bluecoloredPassword") as String? ?: System.getenv("BLUECOLORED_PASSWORD")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-04 00:18:45 +01:00
|
|
|
publications {
|
|
|
|
create<MavenPublication>("maven") {
|
|
|
|
groupId = project.group.toString()
|
|
|
|
artifactId = project.name
|
|
|
|
version = project.version.toString()
|
|
|
|
|
|
|
|
from(components["java"])
|
2024-04-04 02:07:09 +02:00
|
|
|
|
|
|
|
versionMapping {
|
|
|
|
usage("java-api") {
|
|
|
|
fromResolutionOf("runtimeClasspath")
|
|
|
|
}
|
|
|
|
}
|
2022-12-04 00:18:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|