Hi, I'm learning a bit ksp and I would like to kno...
# ksp
m
Hi, I'm learning a bit ksp and I would like to know how could I pass a file to my
SymbolProcessorProvider
? I tried to pass its relative path as ksp argument like this:
Copy code
ksp {
    arg("the-file", "src/main/resources/my-file.txt")
}
But then, is there a way to get the root directory of the gradle module which called my ksp processor?
m
Only way I've found to do this is to burn the file in the processor jar. Example here
m
Hmmmm, Right now, I have an ugly solution like this
Copy code
val SymbolProcessorEnvironment.moduleDirectory: File?
    get() {
        codeGenerator.createNewFileByPath(Dependencies(false), "codegen", "txt").close()
        val file = codeGenerator.generatedFile.firstOrNull { it.name == "codegen.txt" } ?: return null

        var counter = 0
        var buildDirectory: File? = null
        var currentDirectory: File? = file

        while(buildDirectory == null && counter < 7 && currentDirectory != null) {
            if(currentDirectory.name == "build") {
                buildDirectory = currentDirectory
            }

            currentDirectory = currentDirectory.parentFile
            counter++
        }

        return buildDirectory?.parentFile
    }
But that´s very sad there is no existing solution 😞
e
I imagine you'll want to declare the file as an input or output to the ksp task in Gradle so that it can do proper tracking, and then setting the full path as arg shouldn't be much more work than that
m
This works and gives the right file path:
Copy code
ksp {
    arg("the-file", project.file("src/main/resources/my-file.txt").path)
}
e
Gradle won't know to invalidate the task cache when the file changes that way though
1
🫠 2
that's why androidx.room introduced its own Gradle plugin for example, https://developer.android.com/jetpack/androidx/releases/room#2.6.0-alpha02