Skip to content

Commit 3af092e

Browse files
authored
Build File Cleanup (#320)
* replaced `implementation(netty-all` with `api(platform("io.netty:netty-bom` to eliminate need to specify netty version in apps that use DBOS * make jspecify an api dependency instead of compile only * spotless for kotlin * kotlin build files * Remove unneeded jackson-datatype-jsr310 dependency from cli
1 parent 053241c commit 3af092e

6 files changed

Lines changed: 420 additions & 416 deletions

File tree

build.gradle.kts

Lines changed: 126 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,170 @@
11
plugins {
2-
id("pmd")
3-
id("com.diffplug.spotless") version "8.3.0"
4-
id("com.github.ben-manes.versions") version "0.53.0"
2+
id("pmd")
3+
id("com.diffplug.spotless") version "8.3.0"
4+
id("com.github.ben-manes.versions") version "0.53.0"
55
}
66

77
fun runCommand(vararg args: String): String {
8-
val process = ProcessBuilder(*args)
9-
.directory(rootDir)
10-
.redirectErrorStream(true)
11-
.start()
12-
13-
val output = process.inputStream.bufferedReader().readText()
14-
val exitCode = process.waitFor()
15-
16-
if (exitCode != 0) {
17-
throw GradleException("Command failed with exit code $exitCode: ${args.joinToString(" ")}")
18-
}
19-
20-
return output.trim()
21-
}
8+
val process = ProcessBuilder(*args).directory(rootDir).redirectErrorStream(true).start()
9+
10+
val output = process.inputStream.bufferedReader().readText()
11+
val exitCode = process.waitFor()
2212

23-
val gitHash: String by lazy {
24-
runCommand("git", "rev-parse", "--short", "HEAD")
13+
if (exitCode != 0) {
14+
throw GradleException("Command failed with exit code $exitCode: ${args.joinToString(" ")}")
15+
}
16+
17+
return output.trim()
2518
}
2619

20+
val gitHash: String by lazy { runCommand("git", "rev-parse", "--short", "HEAD") }
21+
2722
val gitTag: String? by lazy {
28-
runCatching {
29-
runCommand("git", "describe", "--abbrev=0", "--tags")
30-
}.getOrNull()
23+
runCatching { runCommand("git", "describe", "--abbrev=0", "--tags") }.getOrNull()
3124
}
3225

3326
val commitCount: Int by lazy {
34-
val range = if (gitTag.isNullOrEmpty()) "HEAD" else "$gitTag..HEAD"
35-
runCommand("git", "rev-list", "--count", range).toInt()
27+
val range = if (gitTag.isNullOrEmpty()) "HEAD" else "$gitTag..HEAD"
28+
runCommand("git", "rev-list", "--count", range).toInt()
3629
}
3730

3831
val branch: String by lazy {
39-
// First, try GitHub Actions environment variable
40-
val githubBranch = System.getenv("GITHUB_REF_NAME")
41-
if (!githubBranch.isNullOrBlank()) githubBranch
42-
43-
// Fallback to local git command
44-
else {
45-
runCommand("git", "rev-parse", "--abbrev-ref", "HEAD")
46-
}
32+
// First, try GitHub Actions environment variable
33+
val githubBranch = System.getenv("GITHUB_REF_NAME")
34+
if (!githubBranch.isNullOrBlank()) githubBranch
35+
36+
// Fallback to local git command
37+
else {
38+
runCommand("git", "rev-parse", "--abbrev-ref", "HEAD")
39+
}
4740
}
4841

4942
fun parseTag(tag: String): Triple<Int, Int, Int>? {
50-
val regex = Regex("""v?(\d+)\.(\d+)\.(\d+)""")
51-
val match = regex.matchEntire(tag.trim()) ?: return null
52-
val (major, minor, patch) = match.destructured
53-
return Triple(major.toInt(), minor.toInt(), patch.toInt())
43+
val regex = Regex("""v?(\d+)\.(\d+)\.(\d+)""")
44+
val match = regex.matchEntire(tag.trim()) ?: return null
45+
val (major, minor, patch) = match.destructured
46+
return Triple(major.toInt(), minor.toInt(), patch.toInt())
5447
}
5548

5649
fun calcVersion(): String {
57-
var (major, minor, patch) = parseTag(gitTag ?: "") ?: Triple(0, 1, 0)
50+
var (major, minor, patch) = parseTag(gitTag ?: "") ?: Triple(0, 1, 0)
5851

59-
if (branch == "main") {
60-
return "$major.${minor + 1}.$patch-m$commitCount"
61-
}
52+
if (branch == "main") {
53+
return "$major.${minor + 1}.$patch-m$commitCount"
54+
}
6255

63-
if (branch.startsWith("release/v")) {
64-
if (commitCount == 0) {
65-
return "$major.$minor.$patch"
66-
} else {
67-
return "$major.$minor.${patch + 1}-rc$commitCount"
68-
}
56+
if (branch.startsWith("release/v")) {
57+
if (commitCount == 0) {
58+
return "$major.$minor.$patch"
59+
} else {
60+
return "$major.$minor.${patch + 1}-rc$commitCount"
6961
}
62+
}
7063

71-
return "$major.${minor + 1}.$patch-a$commitCount-g$gitHash"
64+
return "$major.${minor + 1}.$patch-a$commitCount-g$gitHash"
7265
}
7366

74-
val calculatedVersion: String by lazy {
75-
calcVersion()
76-
}
67+
val calculatedVersion: String by lazy { calcVersion() }
7768

7869
// prints when Gradle evaluates the build
79-
println("DBOS Transact version: $calculatedVersion")
70+
println("DBOS Transact version: $calculatedVersion")
8071

8172
allprojects {
82-
group = "dev.dbos"
83-
version = calculatedVersion
84-
extra["commitCount"] = "$commitCount"
73+
group = "dev.dbos"
74+
version = calculatedVersion
75+
extra["commitCount"] = "$commitCount"
76+
77+
repositories {
78+
mavenCentral()
79+
gradlePluginPortal()
80+
}
81+
}
8582

86-
repositories {
87-
mavenCentral()
88-
gradlePluginPortal()
89-
}
83+
spotless {
84+
kotlinGradle {
85+
target("*.gradle.kts")
86+
ktfmt("0.61").googleStyle()
87+
trimTrailingWhitespace()
88+
endWithNewline()
89+
}
9090
}
9191

9292
subprojects {
93-
apply(plugin = "java")
94-
apply(plugin = "pmd")
95-
apply(plugin = "com.diffplug.spotless")
96-
apply(plugin = "com.github.ben-manes.versions")
97-
98-
// PMD configuration
99-
extensions.configure<org.gradle.api.plugins.quality.PmdExtension> {
100-
toolVersion = "7.16.0"
101-
ruleSets = listOf() // disable defaults
102-
ruleSetFiles = files("${rootDir}/config/pmd/ruleset.xml")
103-
isConsoleOutput = true
93+
apply(plugin = "java")
94+
apply(plugin = "pmd")
95+
apply(plugin = "com.diffplug.spotless")
96+
apply(plugin = "com.github.ben-manes.versions")
97+
98+
// PMD configuration
99+
extensions.configure<org.gradle.api.plugins.quality.PmdExtension> {
100+
toolVersion = "7.16.0"
101+
ruleSets = listOf() // disable defaults
102+
ruleSetFiles = files("${rootDir}/config/pmd/ruleset.xml")
103+
isConsoleOutput = true
104+
}
105+
106+
// Spotless configuration
107+
extensions.configure<com.diffplug.gradle.spotless.SpotlessExtension> {
108+
java {
109+
googleJavaFormat()
110+
importOrder("dev.dbos", "java", "javax", "")
111+
removeUnusedImports()
112+
trimTrailingWhitespace()
113+
endWithNewline()
104114
}
105-
106-
// Spotless configuration
107-
extensions.configure<com.diffplug.gradle.spotless.SpotlessExtension> {
108-
java {
109-
googleJavaFormat()
110-
importOrder("dev.dbos", "java", "javax", "")
111-
removeUnusedImports()
112-
trimTrailingWhitespace()
113-
endWithNewline()
114-
}
115+
kotlin {
116+
target("**/*.kt")
117+
targetExclude("build/**/*.kt")
118+
ktfmt("0.61").googleStyle()
119+
trimTrailingWhitespace()
120+
endWithNewline()
115121
}
116-
117-
tasks.withType<com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask> {
118-
rejectVersionIf {
119-
val isUnstable = listOf("alpha", "beta", "rc", "cr", "m", "preview", "b", "ea")
120-
.any { qualifier -> candidate.version.lowercase().contains(qualifier) }
121-
122-
val isStable = listOf("release", "final", "ga")
123-
.any { qualifier -> currentVersion.lowercase().contains(qualifier) }
124-
125-
isUnstable && !isStable
126-
}
122+
kotlinGradle {
123+
target("**/*.gradle.kts")
124+
ktfmt("0.61").googleStyle()
125+
trimTrailingWhitespace()
126+
endWithNewline()
127127
}
128+
}
128129

129-
plugins.withId("java") {
130-
// Force the published bytecode to be Java 17
131-
extensions.getByType<JavaPluginExtension>().apply {
132-
sourceCompatibility = JavaVersion.VERSION_17
133-
targetCompatibility = JavaVersion.VERSION_17
130+
tasks.withType<com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask> {
131+
rejectVersionIf {
132+
val isUnstable =
133+
listOf("alpha", "beta", "rc", "cr", "m", "preview", "b", "ea").any { qualifier ->
134+
candidate.version.lowercase().contains(qualifier)
134135
}
135136

136-
// Allow the compiler to see higher-version APIs for reflection but keep the bytecode target at 17.
137-
tasks.withType<JavaCompile> {
138-
options.release.set(17)
137+
val isStable =
138+
listOf("release", "final", "ga").any { qualifier ->
139+
currentVersion.lowercase().contains(qualifier)
139140
}
140141

141-
// use the environment's JDK instead of the toolchain's JDK for tests
142-
tasks.withType<Test> {
143-
javaLauncher.set(null as JavaLauncher?)
144-
}
142+
isUnstable && !isStable
143+
}
144+
}
145145

146-
tasks.named<Jar>("jar") {
147-
manifest {
148-
attributes["Implementation-Version"] = project.version
149-
attributes["Implementation-Title"] = project.name
150-
attributes["Implementation-Vendor"] = "DBOS, Inc"
151-
attributes["Implementation-Vendor-Id"] = project.group
152-
attributes["SCM-Revision"] = gitHash
153-
}
154-
}
146+
plugins.withId("java") {
147+
// Force the published bytecode to be Java 17
148+
extensions.getByType<JavaPluginExtension>().apply {
149+
sourceCompatibility = JavaVersion.VERSION_17
150+
targetCompatibility = JavaVersion.VERSION_17
155151
}
156-
}
152+
153+
// Allow the compiler to see higher-version APIs for reflection but keep the bytecode target at
154+
// 17.
155+
tasks.withType<JavaCompile> { options.release.set(17) }
156+
157+
// use the environment's JDK instead of the toolchain's JDK for tests
158+
tasks.withType<Test> { javaLauncher.set(null as JavaLauncher?) }
159+
160+
tasks.named<Jar>("jar") {
161+
manifest {
162+
attributes["Implementation-Version"] = project.version
163+
attributes["Implementation-Title"] = project.name
164+
attributes["Implementation-Vendor"] = "DBOS, Inc"
165+
attributes["Implementation-Vendor-Id"] = project.group
166+
attributes["SCM-Revision"] = gitHash
167+
}
168+
}
169+
}
170+
}

settings.gradle.kts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
rootProject.name = "dbos-transact-java"
2+
23
include("transact", "transact-cli")
34

4-
plugins {
5-
id("org.gradle.toolchains.foojay-resolver") version "1.0.0"
6-
}
5+
plugins { id("org.gradle.toolchains.foojay-resolver") version "1.0.0" }
76

87
toolchainManagement {
9-
jvm {
10-
javaRepositories {
11-
repository("foojay") {
12-
resolverClass.set(org.gradle.toolchains.foojay.FoojayToolchainResolver::class.java)
13-
}
14-
}
8+
jvm {
9+
javaRepositories {
10+
repository("foojay") {
11+
resolverClass.set(org.gradle.toolchains.foojay.FoojayToolchainResolver::class.java)
12+
}
1513
}
14+
}
1615
}

0 commit comments

Comments
 (0)