1
1
import java.time.Duration
2
2
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
3
3
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
4
+ import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
4
5
5
6
val assertjVersion = " 3.27.3"
6
7
val kotlinLoggingVersion = " 3.0.5"
@@ -10,7 +11,6 @@ val mockWebServerVersion = "4.12.0"
10
11
val jacksonVersion = " 2.19.0"
11
12
val nettyVersion = " 4.2.2.Final"
12
13
val junitJupiterVersion = " 5.13.0"
13
- val kotlinVersion = " 2.1.21"
14
14
val freemarkerVersion = " 2.3.34"
15
15
val kotestVersion = " 5.9.1"
16
16
val bouncyCastleVersion = " 1.81"
@@ -24,7 +24,7 @@ val mainClassKt = "no.nav.security.mock.oauth2.StandaloneMockOAuth2ServerKt"
24
24
25
25
plugins {
26
26
application
27
- kotlin( " jvm" ) version " 2.1.21 "
27
+ alias(libs.plugins.kotlin. jvm) // refers to plugin declared in gradle/libs.versions.toml
28
28
id(" se.patrikerdes.use-latest-versions" ) version " 0.2.18"
29
29
id(" com.github.ben-manes.versions" ) version " 0.52.0"
30
30
id(" org.jmailen.kotlinter" ) version " 5.1.0"
@@ -49,6 +49,28 @@ java {
49
49
withSourcesJar()
50
50
}
51
51
52
+ kotlin {
53
+ val kotlinTarget = libs.versions.kotlinTarget
54
+ val kotlinTargetVersion = kotlinTarget.map {
55
+ KotlinVersion .fromVersion(it.toKotlinMinor())
56
+ }
57
+
58
+ compilerOptions {
59
+ languageVersion = kotlinTargetVersion
60
+ apiVersion = kotlinTargetVersion
61
+ // Syncing Kotlin JVM target with Java plugin JVM target
62
+ jvmTarget = JvmTarget .JVM_17
63
+ }
64
+
65
+ // Setting core libraries version to manage compile and runtime dependencies exposed in the published artifact metadata
66
+ // These will become transitive dependencies for our users.
67
+ // Core libraries for JVM are kotlin-stdlib and kotlin-test.
68
+ coreLibrariesVersion = kotlinTarget.get()
69
+ }
70
+
71
+ // 1.7.21 => 1.7, 1.9 => 1.9
72
+ fun String.toKotlinMinor () = split(" ." ).take(2 ).joinToString(" ." )
73
+
52
74
apply (plugin = " org.jmailen.kotlinter" )
53
75
54
76
repositories {
@@ -73,7 +95,7 @@ dependencies {
73
95
testImplementation(" org.junit.jupiter:junit-jupiter-params:$junitJupiterVersion " )
74
96
testImplementation(" io.kotest:kotest-runner-junit5-jvm:$kotestVersion " ) // for kotest framework
75
97
testImplementation(" io.kotest:kotest-assertions-core-jvm:$kotestVersion " ) // for kotest core jvm assertions
76
- testImplementation(" org.jetbrains.kotlin:kotlin-test-junit5: $kotlinVersion " )
98
+ testImplementation(" org.jetbrains.kotlin:kotlin-test-junit5" ) // uses version matching kotlin-jvm plugin
77
99
testRuntimeOnly(" org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion " )
78
100
// example use with different frameworks
79
101
testImplementation(" org.springframework.boot:spring-boot-starter-webflux:$springBootVersion " )
@@ -289,12 +311,6 @@ tasks {
289
311
}
290
312
}
291
313
292
- withType< org.jetbrains.kotlin.gradle.tasks.KotlinCompile > {
293
- compilerOptions {
294
- jvmTarget.set(JvmTarget .JVM_17 )
295
- }
296
- }
297
-
298
314
withType<Test > {
299
315
jvmArgs(" --add-opens=java.base/java.util=ALL-UNNAMED" )
300
316
useJUnitPlatform()
@@ -311,6 +327,6 @@ tasks {
311
327
}
312
328
313
329
withType<Wrapper > {
314
- gradleVersion = " 8.9 "
330
+ gradleVersion = " 8.14.1 "
315
331
}
316
332
}
0 commit comments