BlueMapAPI/build.gradle.kts

109 lines
2.7 KiB
Plaintext
Raw Normal View History

2022-07-26 21:21:32 +02:00
import java.io.IOException
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 { 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-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)")
2022-08-01 23:10:19 +02:00
group = "de.bluecolored.bluemap.api"
version = lastVersion +
(if (commits == "0") "" else "-$commits") +
(if (clean) "" else "-dirty")
println("Version: $version")
2022-01-16 14:19:43 +01:00
val javaTarget = 11
java {
2022-07-05 12:50:26 +02:00
sourceCompatibility = JavaVersion.toVersion(javaTarget)
targetCompatibility = JavaVersion.toVersion(javaTarget)
}
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/"
)
}
}
}
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 {
publications {
create<MavenPublication>("maven") {
groupId = project.group.toString()
artifactId = project.name
version = project.version.toString()
from(components["java"])
}
}
}