https://kotlinlang.org logo
Title
r

Rafael Costa

10/04/2021, 12:06 AM
Hi all! I was wondering, is checking if the app has some dependency a valid use case when using KSP? Like imagine, if the user of my KSP library has a certain dependency, then I want to generate some classes a bit differently? I seemingly managed to do this by calling
resolver.getDeclarationsFromPackage("com.some.package").iterator().hasNext()
, but I was wondering if there is a better/more performant way.
We use get class declaration by name
r

Rafael Costa

10/04/2021, 12:16 AM
I see. Cool, thanks @yigit! This is a nice validation that I’m supposed to do this and it’s not a hacky approach 😄
y

yigit

10/04/2021, 12:19 AM
Yep. This significantly improves use experience as you can tell them what to add as a dependency, instead of a class not found compilation failure
r

Rafael Costa

10/04/2021, 12:31 AM
In my case, I want to support both cases where he has or doesn’t have a specific dependency. But actually, now that you mention it, I do have dependencies which I just documented, but if they are not included, then yeah: compilation failure 😛 And we should not rely on documentation only, so.. great! I have more work to do ahah