From 228551b80600d61a936944dd384a350c976f188f Mon Sep 17 00:00:00 2001 From: Hakan Mehmed Date: Thu, 16 Oct 2025 20:40:27 +0000 Subject: [PATCH] Show KSP1 warning only once per project Fixes #2635 --- .../kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt | 5 ++++- .../kotlin/com/google/devtools/ksp/test/VersionCheckIT.kt | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt b/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt index b2b3848d36..463bb572b8 100644 --- a/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt +++ b/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt @@ -219,6 +219,8 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool private val androidComponentCache = ConcurrentHashMap() + private var ksp1WarningShown = false + override fun apply(target: Project) { val ksp = target.extensions.create("ksp", KspExtension::class.java) ksp.useKsp2.convention( @@ -252,12 +254,13 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool val useKsp2 = project.extensions.getByType(KspExtension::class.java).useKsp2.get() - if (useKsp2.not()) { + if (useKsp2.not() && ksp1WarningShown.not()) { project.logger.warn( "We noticed you are using KSP1 which is deprecated and support for it will be removed soon - " + "please migrate to KSP2 as soon as possible. KSP1 will no longer be compatible with" + " Android Gradle Plugin 9.0.0 (and above) and Kotlin 2.3.0 (and above)" ) + ksp1WarningShown = true } // Check version and show warning by default. diff --git a/integration-tests/src/test/kotlin/com/google/devtools/ksp/test/VersionCheckIT.kt b/integration-tests/src/test/kotlin/com/google/devtools/ksp/test/VersionCheckIT.kt index 6943e1167b..baa2fd58f3 100644 --- a/integration-tests/src/test/kotlin/com/google/devtools/ksp/test/VersionCheckIT.kt +++ b/integration-tests/src/test/kotlin/com/google/devtools/ksp/test/VersionCheckIT.kt @@ -14,6 +14,11 @@ class VersionCheckIT(val useKSP2: Boolean) { @JvmField val project: TemporaryTestProject = TemporaryTestProject("playground", useKSP2 = useKSP2) + fun String.containsOnce(substring: String, ignoreCase: Boolean = false): Boolean { + val firstIndex = this.indexOf(substring, ignoreCase = ignoreCase) + return firstIndex != -1 && firstIndex == this.lastIndexOf(substring, ignoreCase = ignoreCase) + } + @Test fun testKsp1Usage() { Assume.assumeFalse(useKSP2) @@ -23,7 +28,7 @@ class VersionCheckIT(val useKSP2: Boolean) { ).run() Assert.assertTrue( - result.output.contains( + result.output.containsOnce( "We noticed you are using KSP1 which is deprecated and support for it will be removed " + "soon - please migrate to KSP2 as soon as possible. KSP1 will no " + "longer be compatible with Android Gradle Plugin 9.0.0 (and above) and Kotlin 2.3.0 (and above)"