11plugins {
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
77fun 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+
2722val 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
3326val 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
3831val 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
4942fun 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
5649fun 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
8172allprojects {
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
9292subprojects {
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+ }
0 commit comments