BlueMapAPI/build.gradle.kts

136 lines
3.8 KiB
Plaintext
Raw Permalink Normal View History

2022-07-26 21:21:32 +02:00
import java.io.IOException
import java.util.concurrent.TimeoutException
2022-07-26 21:21:32 +02:00
plugins {
2022-07-05 12:50:26 +02:00
java
`java-library`
2022-10-13 21:36:17 +02:00
`maven-publish`
2022-07-05 12:50:26 +02:00
id("com.diffplug.spotless") version "6.1.2"
}
2022-07-26 21:21:32 +02:00
fun String.runCommand(): String = ProcessBuilder(split("\\s(?=(?:[^'\"`]*(['\"`])[^'\"`]*\\1)*[^'\"`]*$)".toRegex()))
.directory(projectDir)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start()
.apply {
if (!waitFor(10, TimeUnit.SECONDS)) {
throw TimeoutException("Failed to execute command: '" + this@runCommand + "'")
}
}
2022-07-26 21:21:32 +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()
val clean = "git status --porcelain".runCommand().isEmpty()
2022-08-01 23:10:19 +02:00
val lastTag = "git describe --tags --abbrev=0".runCommand()
val lastVersion = lastTag.substring(1) // remove the leading 'v'
val commits = "git rev-list --count $lastTag..HEAD".runCommand()
2022-07-26 21:21:32 +02:00
println("Git hash: $gitHash" + if (clean) "" else " (dirty)")
2024-04-03 23:02:41 +02:00
group = "de.bluecolored.bluemap"
2022-08-01 23:10:19 +02:00
version = lastVersion +
(if (commits == "0") "" else "-$commits") +
(if (clean) "" else "-dirty")
println("Version: $version")
2024-04-03 21:58:13 +02:00
val javaTarget = 16
java {
2022-07-05 12:50:26 +02:00
sourceCompatibility = JavaVersion.toVersion(javaTarget)
targetCompatibility = JavaVersion.toVersion(javaTarget)
2023-06-26 16:31:44 +02:00
withSourcesJar()
withJavadocJar()
}
repositories {
2022-07-05 12:50:26 +02:00
mavenCentral()
}
dependencies {
2022-07-05 12:50:26 +02:00
api ("com.flowpowered:flow-math:1.0.3")
2022-07-24 00:45:49 +02:00
api ("com.google.code.gson:gson:2.8.0")
2022-07-05 12:50:26 +02:00
compileOnly ("org.jetbrains:annotations:23.0.0")
}
spotless {
2022-07-05 12:50:26 +02:00
java {
target ("src/*/java/**/*.java")
2022-07-05 12:50:26 +02:00
licenseHeaderFile("LICENSE_HEADER")
indentWithSpaces()
trimTrailingWhitespace()
}
}
tasks.withType(JavaCompile::class).configureEach {
2022-07-05 12:50:26 +02:00
options.apply {
encoding = "utf-8"
}
}
tasks.withType(AbstractArchiveTask::class).configureEach {
2022-07-05 12:50:26 +02:00
isReproducibleFileOrder = true
isPreserveFileTimestamps = false
}
tasks.javadoc {
2022-07-05 12:50:26 +02:00
options {
(this as? StandardJavadocDocletOptions)?.apply {
links(
"https://docs.oracle.com/javase/8/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/",
2022-07-05 12:50:26 +02:00
)
2024-04-04 00:19:54 +02:00
addStringOption("Xdoclint:none", "-quiet")
2024-04-03 22:45:31 +02:00
if (JavaVersion.current().isJava9Compatible)
addBooleanOption("html5", true)
2022-07-05 12:50:26 +02:00
}
}
}
2022-07-24 12:08:13 +02:00
tasks.processResources {
from("src/main/resources") {
include("de/bluecolored/bluemap/api/version.json")
duplicatesStrategy = DuplicatesStrategy.INCLUDE
expand (
"version" to project.version,
2022-07-26 21:21:32 +02:00
"gitHash" to gitHash + if (clean) "" else " (dirty)"
2022-07-24 12:08:13 +02:00
)
}
}
2022-10-13 21:46:41 +02:00
publishing {
2024-04-03 22:45:31 +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)
2024-04-03 22:55:28 +02:00
credentials {
username = project.findProperty("bluecoloredUsername") as String? ?: System.getenv("BLUECOLORED_USERNAME")
password = project.findProperty("bluecoloredPassword") as String? ?: System.getenv("BLUECOLORED_PASSWORD")
2024-04-03 22:45:31 +02:00
}
}
}
2022-10-13 21:46:41 +02:00
publications {
create<MavenPublication>("maven") {
groupId = project.group.toString()
artifactId = project.name
version = project.version.toString()
from(components["java"])
}
}
}