Using KSP, how to set the generation/compilation o...
# getting-started
a
Using KSP, how to set the generation/compilation order of files? Or how to make a generated file depend on another? More in 🧵
I have a custom
SymbolProcessor
that generates
FileA
and
FileB
, where
FileB
imports a class from
FileA
. My current solution is like below, but there's a pretty high chance for the build to fail when it tries to compile
FileB
, saying that
FileA
does not exist.
Copy code
class MySymbolProcessor( 
    private val environment: SymbolProcessorEnvironment,
) : SymbolProcessor {
    override fun process(resolver: Resolver): List<KSAnnotated> {
        /**/ 
        val outputStreamA = environment.codeGenerator.createNewFile( 
            dependencies = Dependencies(false),
            packageName = "com.example", 
            fileName = "FileA", 
        )
        outputStreamA.write(fileAText.toByteArray()) 
    val outputStreamB = environment.codeGenerator.createNewFile( 
            dependencies = Dependencies(false),
            packageName = "com.example", 
            fileName = "FileB", 
        )
        outputStreamB.write(fileBText.toByteArray()) 
        return /**/ 
    }
}