kotlingradle-kotlin-dslkotlin-symbol-processing

What should I do if the files generated by KSP are frequently being automatically deleted?


I'm trying to use KSP to process annotations and generate some code, but I'm encountering a problem. When I modify the upstream code, the downstream module's code doesn't trigger a compilation, and KSP doesn't generate code for it.

My project structure is as follows:

rootProjects
    module-ksp
    module-core
        implementation(project(":module-ksp"))
    module-other
        implementation(project(":module-ksp"))
        implementation(project(":module-core"))

Currently, when I compile the entire project, KSP generates code for all modules correctly. However, if I modify the code in the ksp or core module and then compile, KSP only regenerates code for ksp and core. The code generated by KSP in the other module is automatically deleted, causing reflection exceptions at runtime.

The content of my rootProject's build.gradle.kts is as follows:


plugins {
    id("java")
    kotlin("jvm") version "2.0.21"
    id("com.google.devtools.ksp") version "2.0.21-1.0.25"
}

subprojects {

    apply(plugin = "kotlin")
    apply(plugin = "java")
    apply(plugin = "com.google.devtools.ksp")

    if (name != "module-ksp") {
        dependencies {
            implementation(project(":module-ksp"))
            ksp(project(":module-ksp"))
            val globalImplementationList = arrayOf(
                "it.unimi.dsi:fastutil:8.5.15",
                "com.alibaba:fastjson:2.0.53",
            )
            globalImplementationList.forEach { implementation(it) }
            if (name != "module-core") {
                implementation(project(":module-core"))
            }
        }
    }

}

repositories {
    mavenCentral()
}

In theory, when I modify a module that module-other depends on, KSP should either regenerate the code for the submodule or leave the already generated code untouched.

I want to know what the problem is and how to solve it.


Solution

  • I have already solved this issue. The KSP automatically deleting code is due to a bug in KSP's incremental compilation, not a problem with my configuration. Disabling KSP's incremental compilation will resolve the problem.