I’m developing a Gradle plugin and a KSP library. ...
# plugin-development
g
I’m developing a Gradle plugin and a KSP library. The Gradle plugin handles most of the setup for the KSP library. Suppose I have two modules, A and B, within the same project. Module A depends on Module B, and both modules apply the plugin. I want to add some KSP parameters in Module B that can be accessed by Module A, but I’m not having any success. The build process is correct: Module B compiles first, followed by Module A. However, when I print the KSP parameters in Module A, the parameters from Module B are missing. This behavior makes sense, I believe, but I would still like to access them in Module A. Is it possible? If not, is there any workaround? I want to send some information that only Module B has to Module A, and KSP parameters seem to be a good fit for this purpose. (Minor code in 🧵 )
Gradle Plugin:
Copy code
val kotlin = extensions.getByType(KotlinMultiplatformExtension::class.java)
kotlin.targets.configureEach { target ->
    //get some target data
    extensions.getByType(KspExtension::class.java).apply {
        arg(key, value)
    }
}
KSP Processor:
Copy code
public class ProcessorProvider : SymbolProcessorProvider {
    override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor {
        return Processor(environment.codeGenerator, environment.logger, environment.options)
    }
}

internal class Processor(
    private val codeGenerator: CodeGenerator,
    private val logger: KSPLogger,
    private val options: Map<String, String>
) : SymbolProcessor {

    override fun process(resolver: Resolver): List<KSAnnotated> {
        println("$options")
    }
}
The only way I managed to make this work was by creating a
.properties
file in the
rootProject
build directory and then accessing it. Each module can write to it. I’m not sure if this is the best approach, but
kspArgs
wasn’t working. 🤷