New to KSP here so I got a question. I am building...
# ksp
s
New to KSP here so I got a question. I am building something in KSP to generate some code according to some annotations. I got the KSP code in a separate module called
:kspProcessors
inside the project, and I am importing it into my module (let’s call it
:app
) where I want the code generated with
add("kspJs", project(":kspProcessors"))
,
add("kspAndroid", project(":kspProcessors"))
and
add("kspIosX64", project(":kspProcessors"))
. Thing is, inside my KSP, code, it’d be very convenient to have access to the classes that exist inside my
:app
module, to more easily reference them in the code I generate. But would I not then introduce a circular dependency if
:kspProcessors
was depending on
:app
with
implementation(project(":app"))
and had
:app
depend on the ksp module as I am describing above? Would I need to keep the KSP code inside the same module? Maybe there’s no circular dep if one depends on the other using
implementation
and the other using
ksp
? I do not know if I am wording my question as well as I could’ve since I am totally not familiar with how to work with KSP in general, so please ask clarifying questions if I can make something more understandable.
w
I think you’d have the same problem with regular annotation processing, and that the typical solution is to have
processor-api
project with annotations/types that you’d like to share, and just depend on it from both processor and app code
s
Ah yeah that makes sense, I guess whenever there’s such problems the solution is always a new module with just the API which can be shared 😄 Currently in my generated code I’m literally manually putting some package and class names, which does work but is so brittle in case of changes. Thanks a lot for your input, at least now I know what my options are, I really appreciate it 🙌
w
Hardcoding class names is that terrible if the processor is in the same build anyway, I think IJ is usually smart enough to recognize the string references when refactoring. But if you want safety then yeah, I’d just have a separate API module
s
Yeah that is true, it’s a simple processor for our own internal use, not necessarily something that others would use, so in the end I may never introduce the new API module and rely on IntelliJ magic to hold my hand so I don’t break stuff 😅