-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle.kts
129 lines (110 loc) · 3.76 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import java.io.IOException
import java.util.concurrent.TimeoutException
plugins {
java
`java-library`
`maven-publish`
id("com.diffplug.spotless") version "6.1.2"
}
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 + "'")
}
.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()
val lastTag = "git describe --tags --abbrev=0".runCommand()
val lastVersion = if (lastTag.isEmpty()) "dev" else lastTag.substring(1) // remove the leading 'v'
val commits = "git rev-list --count $lastTag..HEAD".runCommand()
println("Git hash: $gitHash" + if (clean) "" else " (dirty)")
group = "de.bluecolored"
version = lastVersion +
(if (commits == "0") "" else "-$commits") +
(if (clean) "" else "-dirty")
println("Version: $version")
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
withSourcesJar()
withJavadocJar()
}
repositories {
mavenCentral()
}
dependencies {
compileOnly ("org.jetbrains:annotations:24.0.1")
compileOnly ("org.projectlombok:lombok:1.18.32")
annotationProcessor ("org.projectlombok:lombok:1.18.32")
testImplementation ("org.junit.jupiter:junit-jupiter-api:5.9.2")
testRuntimeOnly ("org.junit.jupiter:junit-jupiter-engine:5.9.2")
testCompileOnly ("org.projectlombok:lombok:1.18.32")
testAnnotationProcessor ("org.projectlombok:lombok:1.18.32")
}
tasks.getByName<Test>("test") {
useJUnitPlatform()
}
spotless {
java {
target ("src/*/java/**/*.java")
licenseHeaderFile("LICENSE_HEADER")
indentWithSpaces()
trimTrailingWhitespace()
}
}
tasks.withType(JavaCompile::class).configureEach {
options.apply {
encoding = "utf-8"
}
}
tasks.withType(Javadoc::class) {
options {
this as StandardJavadocDocletOptions // unsafe cast
addStringOption("Xdoclint:none", "-quiet")
}
}
tasks.withType(AbstractArchiveTask::class).configureEach {
isReproducibleFileOrder = true
isPreserveFileTimestamps = false
}
tasks.javadoc {
options {
(this as? StandardJavadocDocletOptions)?.apply {
links(
"https://docs.oracle.com/en/java/javase/21/docs/api/",
)
addStringOption("Xdoclint:none", "-quiet")
if (JavaVersion.current().isJava9Compatible)
addBooleanOption("html5", true)
}
}
}
publishing {
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")
}
}
}
publications {
create<MavenPublication>("maven") {
groupId = project.group.toString()
artifactId = project.name
version = project.version.toString()
from(components["java"])
}
}
}