Hi! Is there some way to retrieve the name of the ...
# ksp
g
Hi! Is there some way to retrieve the name of the current module being processed? (I'm generating documentation on a multi-module project.)
t
If you are talking about Gradle modules, not that I'm aware of in KSP directly. Maybe try passing it via processor options in the
ksp{}
extension in build scripts?
g
Yes, thanks. I need to operate on a lot of modules, using the
originFile
path for now to deduce the module name, quite limited indeed. I suppose I could add a gradle plugin to pass automatically the value from gradle to ksp 🤔 I was hoping something from KSP environment, not sure if it makes sense.
a
For now, this super bad solution seems to work
Copy code
fun moduleName(resolver: Resolver): String {
    val moduleDescriptor = resolver::class.java
        .getDeclaredField("module")
        .apply { isAccessible = true }
        .get(resolver)
    val rawName = moduleDescriptor::class.java
        .getMethod("getName")
        .invoke(moduleDescriptor)
        .toString()
    return rawName
        .removeSurrounding("<", ">")
        .removeSuffix("_debug")
        .removeSuffix("_release")
}
j
I would recommend to not rely on reflection. I think this
moduleName
thing was considered long ago, and I can’t think of any objections to this, but as we are approaching to our next release, this probably won’t be shipped until next next release.
a
Can I create github enhancement issue?
j
sure, that’s even better!
a
🙏 3