Skip to content

Commit e7b0be1

Browse files
authored
feat: enable kotlin support (#988)
* feat: enable kotlin support * bug: remove gradle dependency verification metadata
1 parent ca6ad7a commit e7b0be1

13 files changed

Lines changed: 168 additions & 7683 deletions

File tree

build-logic/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ plugins {
66
fun Provider<PluginDependency>.asDep() =
77
map { "${it.pluginId}:${it.pluginId}.gradle.plugin:${it.version}" }
88

9+
repositories {
10+
gradlePluginPortal()
11+
mavenCentral()
12+
}
13+
914
dependencies {
1015
implementation(libs.plugins.spotless.asDep())
16+
implementation(libs.plugins.kotlin.jvm.asDep())
1117
implementation(libs.plugins.errorprone.asDep())
1218
implementation(libs.plugins.animalsniffer.asDep())
1319
implementation(libs.plugins.vanniktech.publish.asDep())
@@ -22,4 +28,5 @@ buildConfig {
2228
buildConfigField("JACOCO", libs.versions.jacoco)
2329
buildConfigField("PALANTIR_FORMAT", libs.versions.palantir.format)
2430
buildConfigField("GUMMY_BEARS", libs.versions.gummy.bears)
31+
buildConfigField("KTFMT", libs.versions.ktfmt)
2532
}

build-logic/gradle/libs.versions.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[versions]
22
# Gradle plugins (used in build.gradle.kts dependencies)
3+
kotlin = "2.3.20"
34
spotless = "8.2.1"
45
errorprone-gradle = "5.0.0"
56
animalsniffer = "2.0.1"
@@ -12,10 +13,12 @@ error-prone-core = "2.42.0"
1213
jacoco = "0.8.14"
1314
palantir-format = "2.88.0"
1415
gummy-bears = "0.12.0"
16+
ktfmt = "0.53"
1517

1618
[plugins]
1719
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
1820
errorprone = { id = "net.ltgt.errorprone", version.ref = "errorprone-gradle" }
1921
animalsniffer = { id = "ru.vyarus.animalsniffer", version.ref = "animalsniffer" }
2022
buildconfig = { id = "com.github.gmazzo.buildconfig", version.ref = "buildconfig" }
2123
vanniktech-publish = { id = "com.vanniktech.maven.publish", version.ref = "vanniktech-publish" }
24+
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
plugins {
2+
id("cqf.java-conventions")
3+
kotlin("jvm")
4+
}
5+
6+
kotlin {
7+
// Align the Kotlin JVM target with the Java toolchain already configured
8+
// by cqf.java-conventions. Using jvmToolchain here also sets the JVM
9+
// target for the Kotlin compiler so the two don't diverge.
10+
jvmToolchain(17)
11+
12+
// Allow .kt files to live alongside .java files in src/main/java and
13+
// src/test/java. The Kotlin compiler picks up .kt files from these dirs;
14+
// the Java compiler independently processes .java files there as before.
15+
sourceSets {
16+
main {
17+
kotlin.srcDir("src/main/java")
18+
}
19+
test {
20+
kotlin.srcDir("src/test/java")
21+
}
22+
}
23+
}

build-logic/src/main/kotlin/cqf.spotless-conventions.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,11 @@ spotless {
66
java {
77
palantirJavaFormat(BuildConfig.PALANTIR_FORMAT)
88
}
9+
kotlin {
10+
ktfmt(BuildConfig.KTFMT).kotlinlangStyle()
11+
}
12+
13+
kotlinGradle {
14+
ktfmt(BuildConfig.KTFMT).kotlinlangStyle()
15+
}
916
}

cqf-fhir-benchmark/build.gradle.kts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ plugins {
66
id("cqf.spotless-conventions")
77
}
88

9-
10-
119
dependencies {
1210
implementation(project(":cqf-fhir-cr"))
1311
implementation(project(":cqf-fhir-test"))
@@ -27,6 +25,4 @@ tasks.withType<JavaCompile>().configureEach {
2725
}
2826

2927
// Benchmarks have no JUnit tests, only JMH benchmarks
30-
tasks.withType<Test>().configureEach {
31-
failOnNoDiscoveredTests = false
32-
}
28+
tasks.withType<Test>().configureEach { failOnNoDiscoveredTests = false }

cqf-fhir-cql/build.gradle.kts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@ plugins {
88

99
dependencies {
1010
api(project(":cqf-fhir-utility"))
11-
api(libs.cql.cqf.fhir) {
12-
exclude(group = "junit", module = "junit")
13-
}
14-
api(libs.cql.cqf.fhir.npm) {
15-
exclude(group = "junit", module = "junit")
16-
}
11+
api(libs.cql.cqf.fhir) { exclude(group = "junit", module = "junit") }
12+
api(libs.cql.cqf.fhir.npm) { exclude(group = "junit", module = "junit") }
1713
api(libs.cql.quick)
1814

1915
// Test dependencies

cqf-fhir-cr-cli/build.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ plugins {
99

1010
// No animal-sniffer for this module
1111

12-
application {
13-
mainClass = "org.opencds.cqf.fhir.cr.cli.Main"
14-
}
12+
application { mainClass = "org.opencds.cqf.fhir.cr.cli.Main" }
1513

1614
tasks.named<org.springframework.boot.gradle.tasks.bundling.BootJar>("bootJar") {
1715
mainClass = "org.opencds.cqf.fhir.cr.cli.Main"

cqf-fhir-cr-hapi/build.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ dependencies {
1111
api(libs.hapi.fhir.converter)
1212
api(project(":cqf-fhir-cr"))
1313
api(project(":cqf-fhir-utility"))
14-
api(libs.hapi.fhir.jpaserver.base) {
15-
exclude(group = "org.glassfish", module = "jakarta.json")
16-
}
14+
api(libs.hapi.fhir.jpaserver.base) { exclude(group = "org.glassfish", module = "jakarta.json") }
1715
api(libs.hapi.fhir.storage) {
1816
exclude(group = "com.sun.activation", module = "jakarta.activation")
1917
}

cqf-fhir-cr/build.gradle.kts

Lines changed: 64 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -24,85 +24,82 @@ dependencies {
2424
}
2525

2626
// Test JAR for downstream modules
27-
val testJar by tasks.registering(Jar::class) {
28-
archiveClassifier = "tests"
29-
from(sourceSets.test.get().output)
30-
}
31-
32-
configurations {
33-
create("testArtifacts") {
34-
extendsFrom(configurations.testImplementation.get())
27+
val testJar by
28+
tasks.registering(Jar::class) {
29+
archiveClassifier = "tests"
30+
from(sourceSets.test.get().output)
3531
}
36-
}
3732

38-
artifacts {
39-
add("testArtifacts", testJar)
40-
}
33+
configurations { create("testArtifacts") { extendsFrom(configurations.testImplementation.get()) } }
34+
35+
artifacts { add("testArtifacts", testJar) }
4136

4237
// Add test JAR to publishing
4338
afterEvaluate {
44-
publishing {
45-
publications {
46-
named<MavenPublication>("maven") {
47-
artifact(testJar)
48-
}
49-
}
50-
}
39+
publishing { publications { named<MavenPublication>("maven") { artifact(testJar) } } }
5140
}
5241

5342
// Generate build properties
54-
val generateBuildProperties by tasks.registering {
55-
val outputDir = layout.buildDirectory.dir("generated-sources/properties")
56-
val propsFile = outputDir.map { it.file("org/opencds/cqf/fhir/cqf-fhir-cr-build.properties") }
57-
val projectVersion = project.version.toString()
58-
59-
outputs.dir(outputDir)
60-
61-
doLast {
62-
val gitCommit = try {
63-
providers.exec {
64-
commandLine("git", "rev-parse", "HEAD")
65-
}.standardOutput.asText.get().trim()
66-
} catch (_: Exception) {
67-
"UNKNOWN"
68-
}
69-
70-
val gitBranch = try {
71-
providers.exec {
72-
commandLine("git", "rev-parse", "--abbrev-ref", "HEAD")
73-
}.standardOutput.asText.get().trim()
74-
} catch (_: Exception) {
75-
"UNKNOWN"
76-
}
77-
78-
val timestamp = OffsetDateTime.now().format(
79-
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SXXX")
80-
)
81-
82-
val timestampRegex = Regex("clinicalreasoning\\.timestamp=.*\\n")
83-
val content = buildString {
84-
appendLine("clinicalreasoning.buildnumber=$gitCommit")
85-
appendLine("clinicalreasoning.timestamp=$timestamp")
86-
appendLine("clinicalreasoning.version=$projectVersion")
87-
appendLine("scmBranch=$gitBranch")
88-
}
43+
val generateBuildProperties by
44+
tasks.registering {
45+
val outputDir = layout.buildDirectory.dir("generated-sources/properties")
46+
val propsFile =
47+
outputDir.map { it.file("org/opencds/cqf/fhir/cqf-fhir-cr-build.properties") }
48+
val projectVersion = project.version.toString()
49+
50+
outputs.dir(outputDir)
51+
52+
doLast {
53+
val gitCommit =
54+
try {
55+
providers
56+
.exec { commandLine("git", "rev-parse", "HEAD") }
57+
.standardOutput
58+
.asText
59+
.get()
60+
.trim()
61+
} catch (_: Exception) {
62+
"UNKNOWN"
63+
}
64+
65+
val gitBranch =
66+
try {
67+
providers
68+
.exec { commandLine("git", "rev-parse", "--abbrev-ref", "HEAD") }
69+
.standardOutput
70+
.asText
71+
.get()
72+
.trim()
73+
} catch (_: Exception) {
74+
"UNKNOWN"
75+
}
76+
77+
val timestamp =
78+
OffsetDateTime.now()
79+
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SXXX"))
80+
81+
val timestampRegex = Regex("clinicalreasoning\\.timestamp=.*\\n")
82+
val content = buildString {
83+
appendLine("clinicalreasoning.buildnumber=$gitCommit")
84+
appendLine("clinicalreasoning.timestamp=$timestamp")
85+
appendLine("clinicalreasoning.version=$projectVersion")
86+
appendLine("scmBranch=$gitBranch")
87+
}
8988

90-
// Only write if meaningful content changed (ignoring the timestamp)
91-
// to avoid triggering IDE file-watcher rebuild loops.
92-
val file = propsFile.get().asFile
93-
file.parentFile.mkdirs()
94-
if (file.exists()) {
95-
val existing = file.readText()
96-
if (existing.replace(timestampRegex, "") == content.replace(timestampRegex, "")) {
97-
return@doLast
89+
// Only write if meaningful content changed (ignoring the timestamp)
90+
// to avoid triggering IDE file-watcher rebuild loops.
91+
val file = propsFile.get().asFile
92+
file.parentFile.mkdirs()
93+
if (file.exists()) {
94+
val existing = file.readText()
95+
if (existing.replace(timestampRegex, "") == content.replace(timestampRegex, "")) {
96+
return@doLast
97+
}
9898
}
99+
file.writeText(content)
99100
}
100-
file.writeText(content)
101101
}
102-
}
103102

104103
sourceSets.main { resources.srcDir(generateBuildProperties.map { it.outputs.files.singleFile }) }
105104

106-
tasks.named("processResources") {
107-
dependsOn(generateBuildProperties)
108-
}
105+
tasks.named("processResources") { dependsOn(generateBuildProperties) }

cqf-fhir-utility/build.gradle.kts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id("cqf.java-conventions")
2+
id("cqf.kotlin-conventions")
33
id("cqf.spotless-conventions")
44
id("cqf.jacoco-conventions")
55
id("cqf.animal-sniffer-conventions")
@@ -9,9 +9,7 @@ plugins {
99
dependencies {
1010
// CQL Engine - api scope since types are used by downstream modules
1111
api(libs.cql.engine)
12-
api(libs.cql.engine.fhir) {
13-
exclude(group = "junit", module = "junit")
14-
}
12+
api(libs.cql.engine.fhir) { exclude(group = "junit", module = "junit") }
1513
api(libs.cql.to.elm.jvm)
1614
api(libs.cql.ucum)
1715
api(libs.cql.elm.fhir)

0 commit comments

Comments
 (0)