-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
264 lines (220 loc) · 7.64 KB
/
build.gradle.kts
File metadata and controls
264 lines (220 loc) · 7.64 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
import com.vanniktech.maven.publish.DeploymentValidation
plugins {
id("pmd")
alias(libs.plugins.spotless)
alias(libs.plugins.versions)
alias(libs.plugins.maven.publish) apply false
alias(libs.plugins.kotlin.jvm) apply false
}
fun runCommand(vararg args: String): String {
val process = ProcessBuilder(*args).directory(rootDir).redirectErrorStream(true).start()
val output = process.inputStream.bufferedReader().readText()
val exitCode = process.waitFor()
if (exitCode != 0) {
throw GradleException("Command failed with exit code $exitCode: ${args.joinToString(" ")}")
}
return output.trim()
}
val gitHash: String by lazy { runCommand("git", "rev-parse", "--short", "HEAD") }
val gitTag: String? by lazy {
runCatching { runCommand("git", "describe", "--abbrev=0", "--tags") }.getOrNull()
}
val commitCount: Int by lazy {
val range = if (gitTag.isNullOrEmpty()) "HEAD" else "$gitTag..HEAD"
runCommand("git", "rev-list", "--count", range).toInt()
}
val branch: String by lazy {
// First, try GitHub Actions environment variable
val githubBranch = System.getenv("GITHUB_REF_NAME")
if (!githubBranch.isNullOrBlank()) githubBranch
// Fallback to local git command
else {
runCommand("git", "rev-parse", "--abbrev-ref", "HEAD")
}
}
fun parseTag(tag: String): Triple<Int, Int, Int>? {
val regex = Regex("""v?(\d+)\.(\d+)\.(\d+)""")
val match = regex.matchEntire(tag.trim()) ?: return null
val (major, minor, patch) = match.destructured
return Triple(major.toInt(), minor.toInt(), patch.toInt())
}
fun calcVersion(): String {
var (major, minor, patch) = parseTag(gitTag ?: "") ?: Triple(0, 1, 0)
if (branch == "main") {
return "$major.${minor + 1}.$patch-m$commitCount"
}
if (branch.startsWith("release/v")) {
if (commitCount == 0) {
return "$major.$minor.$patch"
} else {
return "$major.$minor.${patch + 1}-rc$commitCount"
}
}
return "$major.${minor + 1}.$patch-a$commitCount-g$gitHash"
}
val calculatedVersion: String by lazy { calcVersion() }
// prints when Gradle evaluates the build
println("DBOS Transact version: $calculatedVersion")
allprojects {
group = "dev.dbos"
version = calculatedVersion
extra["commitCount"] = "$commitCount"
repositories {
mavenCentral()
gradlePluginPortal()
}
}
spotless {
kotlinGradle {
target("*.gradle.kts")
ktfmt("0.61").googleStyle()
trimTrailingWhitespace()
endWithNewline()
}
}
val pmdVersion = libs.versions.pmd.get()
extensions.configure<org.gradle.api.plugins.quality.PmdExtension> { toolVersion = pmdVersion }
subprojects {
apply(plugin = "java")
apply(plugin = "pmd")
apply(plugin = "com.diffplug.spotless")
apply(plugin = "com.github.ben-manes.versions")
// PMD configuration
extensions.configure<org.gradle.api.plugins.quality.PmdExtension> {
toolVersion = pmdVersion
ruleSets = listOf() // disable defaults
ruleSetFiles = files("${rootDir}/config/pmd/ruleset.xml")
isConsoleOutput = true
}
// Spotless configuration
extensions.configure<com.diffplug.gradle.spotless.SpotlessExtension> {
java {
googleJavaFormat()
cleanthat()
formatAnnotations()
removeUnusedImports()
importOrder("dev.dbos", "java", "javax", "")
trimTrailingWhitespace()
endWithNewline()
}
kotlin {
target("**/*.kt")
targetExclude("build/**/*.kt")
ktfmt("0.62").googleStyle()
trimTrailingWhitespace()
endWithNewline()
}
kotlinGradle {
target("**/*.gradle.kts")
ktfmt("0.62").googleStyle()
trimTrailingWhitespace()
endWithNewline()
}
}
tasks.withType<com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask> {
rejectVersionIf {
fun isUnstable(version: String) =
listOf("alpha", "beta", "rc", "cr", "m", "preview", "b", "ea").any { qualifier ->
version.lowercase().contains(qualifier)
}
isUnstable(candidate.version) && !isUnstable(currentVersion)
}
}
plugins.withId("java") {
// Force the published bytecode to be Java 17
extensions.getByType<JavaPluginExtension>().apply {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
tasks.withType<JavaCompile> {
options.release.set(17)
options.compilerArgs.addAll(
listOf("-Xlint:unchecked", "-Xlint:deprecation", "-Xlint:rawtypes", "-Werror")
)
}
// use the environment's JDK instead of the toolchain's JDK for tests
tasks.withType<Test> { javaLauncher.set(null as JavaLauncher?) }
tasks.withType<Test> {
useJUnitPlatform()
testLogging {
events("failed")
showStandardStreams = true
showExceptions = true
showCauses = true
showStackTraces = true
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
}
addTestListener(
object : TestListener {
private val failedTests = mutableListOf<String>()
override fun beforeSuite(suite: TestDescriptor) {}
override fun beforeTest(testDescriptor: TestDescriptor) {}
override fun afterTest(testDescriptor: TestDescriptor, result: TestResult) {
if (result.resultType == TestResult.ResultType.FAILURE) {
failedTests.add("${testDescriptor.className}.${testDescriptor.name}")
}
}
override fun afterSuite(suite: TestDescriptor, result: TestResult) {
if (suite.parent == null) {
println("\nTest Results:")
println(" Tests run: ${result.testCount}")
println(" Passed: ${result.successfulTestCount}")
println(" Failed: ${result.failedTestCount}")
println(" Skipped: ${result.skippedTestCount}")
if (failedTests.isNotEmpty()) {
println("\nFailed Tests:")
failedTests.forEach { println(" - $it") }
}
}
}
}
)
}
tasks.named<Jar>("jar") {
manifest {
attributes["Implementation-Version"] = project.version
attributes["Implementation-Title"] = project.name
attributes["Implementation-Vendor"] = "DBOS, Inc"
attributes["Implementation-Vendor-Id"] = project.group
attributes["SCM-Revision"] = gitHash
}
}
}
plugins.withId("com.vanniktech.maven.publish") {
val publishingToMavenCentral =
gradle.startParameter.taskNames.any { it.contains("publishToMavenCentral") }
tasks.withType<Javadoc> {
(options as StandardJavadocDocletOptions).apply {
addStringOption("Xdoclint:all,-missing", "-quiet")
encoding = "UTF-8"
}
}
tasks.named("build") { dependsOn("javadoc") }
extensions.configure<com.vanniktech.maven.publish.MavenPublishBaseExtension> {
publishToMavenCentral(automaticRelease = true, validateDeployment = DeploymentValidation.NONE)
if (publishingToMavenCentral) signAllPublications()
pom {
inceptionYear.set("2025")
url.set("https://github.com/dbos-inc/dbos-transact-java")
licenses {
license {
name.set("MIT License")
url.set("https://opensource.org/licenses/MIT")
}
}
developers {
developer {
id.set("dbos-inc")
name.set("DBOS Inc")
email.set("support@dbos.dev")
}
}
scm {
connection.set("scm:git:git://github.com/dbos-inc/dbos-transact-java.git")
developerConnection.set("scm:git:ssh://github.com:dbos-inc/dbos-transact-java.git")
url.set("https://github.com/dbos-inc/dbos-transact-java/tree/main")
}
}
}
}
}