Gradle build slow due to :kspDebugKotlin task
# ksp
n
Gradle build slow due to :kspDebugKotlin task
Everytime we make a code change (eg: add a log line), kspDebugKotlin step takes 13 seconds and causes issues. I checked the kspDirtySet.log It had these lines Modified Removed Disappeared Outputs Affected By CP Affected By new syms Affected By sealed CP changes Dirty / All: 100.00% below is our gradle.properties
Copy code
org.gradle.jvmargs=-Xmx8g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC -Dkotlin.daemon.jvm.options=-Xmx8g -XX:+HeapDumpOnOutOfMemoryError
android.useAndroidX=true
kotlin.code.style=official
android.nonTransitiveRClass=true
android.nonFinalResIds=false
android.enableJetifier=false
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configureondemand=true
org.gradle.daemon=true
org.gradle.configuration-cache=true
org.gradle.configuration-cache.problems=warn
ksp.incremental=true
ksp.incremental.log=true
what am I missing here? we use these dependencies with ksp
Copy code
ksp "androidx.room:room-compiler:$room_version"
ksp "io.github.raamcosta.compose-destinations:ksp:$raamcostaVersion"
ksp 'androidx.hilt:hilt-compiler:1.2.0'
ksp "com.google.dagger:hilt-compiler:$hilt_version"
In case a dependency is not supporting incremental build, how to find that?
g
You may want to start with that : https://docs.gradle.org/current/userguide/build_cache_debugging.html You could also comment some ksp processor and check if it's better or not (iirc even if the build fails, it may feed the gradle cache, so you may be able to observe differences in logs. If I'm wrong, you may have to change your code to be able to test it, so you may want to start on a very little module or a new sample app to try to reproduce it).
n
Thanks a lot for the quick reply. Trying this. will keep this thread posted
you are a saviour @glureau found out the library that caused this issue and asked help from the author. more details here: https://github.com/raamcosta/compose-destinations/issues/702#issuecomment-2491370951
👌 1
In the below code, getSymbolsWithAnnotation always gives all the files instead of giving incrementally modified alone. why is that? how to fix this?
Copy code
private fun Resolver.getComposableDestinationPaths(
    annotationQualifiedName: String = DESTINATION_ANNOTATION_QUALIFIED,
    annotationsPath: DestinationAnnotationsPath = DestinationAnnotationsPath()
): Sequence<DestinationAnnotationsPath> {
    val symbolsWithAnnotation = getSymbolsWithAnnotation(annotationQualifiedName)

    return symbolsWithAnnotation.flatMap {
        createPaths(
            annotationQualifiedName,
            it,
            annotationsPath.copy()
        )
    }
}
d
always gives all the files instead of giving incrementally modified alone
Could it be that the processor needs to use the
Dependencies
API? There is an explanation here: https://github.com/google/ksp/blob/main/api/src/main/kotlin/com/google/devtools/ksp/processing/CodeGenerator.kt#L59 And also: https://square.github.io/kotlinpoet/interop-ksp/#incremental-processing You can debug the incremental processing by turning on logs: https://kotlinlang.org/docs/ksp-incremental.html#reporting-bugs
n
you are absolutely right @David Rawson processor is using Dependencies API
Copy code
class KspCodeOutputStreamMaker(
    private val codeGenerator: CodeGenerator,
    private val sourceMapper: KSFileSourceMapper
) : CodeOutputStreamMaker {

    override val packageNamesWrittenTo = mutableListOf<String>()

    override fun makeFile(
        name: String,
        packageName: String,
        extensionName: String,
        vararg sourceIds: String
    ): OutputStream {

        val sources = sourceIds.mapNotNull { sourceMapper.mapToKSFile(it) }.toTypedArray()
        val dependencies = if (sources.isEmpty()) {
            Dependencies.ALL_FILES
        } else {
            Dependencies(
                false,
                *sources
            )
        }

        packageNamesWrittenTo.add(packageName)

        return codeGenerator.createNewFile(
            dependencies = dependencies,
            fileName = name,
            packageName = packageName,
            extensionName = extensionName
        )
    }

}
137 Views