Skip to content

Commit 2c735dd

Browse files
committed
Fix deprecation warning of -Xjvm-default Kotlin argument
Gradle files should use `jvmDefault.set(JvmDefaultMode)` instead of `freeCompilerArgs.add(String)`. The `-Xjvm-default` argument should be replaced with `-jvm-default`.
1 parent e8fa23d commit 2c735dd

File tree

8 files changed

+31
-11
lines changed

8 files changed

+31
-11
lines changed

api/build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import com.google.devtools.ksp.configureMetalava
2+
import org.jetbrains.kotlin.gradle.dsl.JvmDefaultMode
23
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
34

45
description = "Kotlin Symbol Processing API"
@@ -7,7 +8,9 @@ val signingKey: String? by project
78
val signingPassword: String? by project
89

910
tasks.withType<KotlinCompile> {
10-
compilerOptions.freeCompilerArgs.add("-Xjvm-default=all-compatibility")
11+
compilerOptions {
12+
jvmDefault.set(JvmDefaultMode.ENABLE)
13+
}
1114
}
1215

1316
plugins {

api/src/main/kotlin/com/google/devtools/ksp/processing/PlatformInfo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ interface JvmPlatformInfo : PlatformInfo {
3434
val jvmTarget: String
3535

3636
/**
37-
* JVM default mode. Correspond to `-Xjvm-default' to Kotlin compiler
37+
* JVM default mode. Correspond to `-jvm-default' to Kotlin compiler
3838
*/
3939
val jvmDefaultMode: String
4040
}

common-deps/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmDefaultMode
2+
13
description = "Kotlin Symbol Processor"
24

35
val junitVersion: String by project
@@ -30,7 +32,7 @@ val dokkaJavadocJar = tasks.register<Jar>("dokkaJavadocJar") {
3032

3133
kotlin {
3234
compilerOptions {
33-
freeCompilerArgs.add("-Xjvm-default=all-compatibility")
35+
jvmDefault.set(JvmDefaultMode.ENABLE)
3436
}
3537
}
3638

common-util/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmDefaultMode
2+
13
description = "Kotlin Symbol Processing Util"
24

35
val junitVersion: String by project
@@ -16,7 +18,7 @@ dependencies {
1618

1719
kotlin {
1820
compilerOptions {
19-
freeCompilerArgs.add("-Xjvm-default=all-compatibility")
21+
jvmDefault.set(JvmDefaultMode.ENABLE)
2022
}
2123
}
2224

gradle-plugin/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmDefaultMode
12
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
23

34
description = "Kotlin Symbol Processor"
@@ -42,7 +43,7 @@ dependencies {
4243

4344
kotlin {
4445
compilerOptions {
45-
freeCompilerArgs.add("-Xjvm-default=all-compatibility")
46+
jvmDefault.set(JvmDefaultMode.ENABLE)
4647
}
4748
}
4849

gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspAATask.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,12 @@ abstract class KspAATask @Inject constructor(
354354

355355
val oldJvmDefaultMode = compileTask.flatMap { task ->
356356
task.compilerOptions.freeCompilerArgs
357-
.map { args -> args.filter { it.startsWith("-Xjvm-default=") } }
357+
.map { args ->
358+
args.filter {
359+
// Support both new and deprecated arguments (-Xjvm-* is deprecated)
360+
it.startsWith("-jvm-default=") || it.startsWith("-Xjvm-default=")
361+
}
362+
}
358363
.map { it.lastOrNull()?.substringAfter("=") ?: "undefined" }
359364
}
360365

integration-tests/src/test/kotlin/com/google/devtools/ksp/test/PlaygroundIT.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,16 @@ class PlaygroundIT() {
309309

310310
@Test
311311
fun testJvmPlatformInfo() {
312-
val kotlinCompile = "org.jetbrains.kotlin.gradle.tasks.KotlinCompile"
313312
val buildFile = File(project.root, "workload/build.gradle.kts")
314-
buildFile.appendText("\ntasks.withType<$kotlinCompile> {")
315-
buildFile.appendText("\n compilerOptions.freeCompilerArgs.add(\"-Xjvm-default=all\")")
316-
buildFile.appendText("\n}")
313+
buildFile.appendText(
314+
"""
315+
|tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
316+
| compilerOptions {
317+
| jvmDefault.set(org.jetbrains.kotlin.gradle.dsl.JvmDefaultMode.NO_COMPATIBILITY)
318+
| }
319+
|}
320+
|""".trimMargin()
321+
)
317322

318323
val gradleRunner = GradleRunner.create().withProjectDir(project.root)
319324
gradleRunner.buildAndCheck("clean", "build") { result ->

test-utils/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmDefaultMode
2+
13
plugins {
24
kotlin("jvm")
35
}
@@ -16,6 +18,6 @@ dependencies {
1618

1719
kotlin {
1820
compilerOptions {
19-
freeCompilerArgs.add("-Xjvm-default=all-compatibility")
21+
jvmDefault.set(JvmDefaultMode.ENABLE)
2022
}
2123
}

0 commit comments

Comments
 (0)