https://kotlinlang.org logo
#ksp
Title
# ksp
m

Manel Martos Roldan

11/13/2023, 7:04 PM
Hey folks! I'm working on a KMP project that utilises KSP for code generation. As usual, I'm using a custom annotation to tag code within the common target module and KSP processor generates new code from that. Project is targeting many platforms (Android, iOS, Web and Desktop). While the project compiles successfully, AS/IntelliJ IDEA isn't able to resolve references to the generated code, impacting the development experience. Additionally, if I change config to only targeting one platform, symbols are resolved successfully. Is there any work around for it and make dev-experience more pleasant?
In case you need it, this is a simple project with similar setup where you can reproduce the issue.
r

rnett

11/13/2023, 9:45 PM
Encountered the same thing, fwiw. Didn't find a solution
t

Ting-Yuan Huang

11/13/2023, 10:56 PM
tl;dr: this will be supported by KSP 2 next year. For now, only symbols that are generated for the target source sets are known by the IDE details: KSP adds generated sources to the default source set of each target compilation, but not common / metadata compilations. IDE knows those source sets via gradle tooling api and IDE plugins. Because of how source sets in KMP are compiled, if KSP adds them to intermediate source sets, they'll be observable in downstream compilations and processors. They would not only be redundant but also break processors' assumptions badly. In KSP 2, this will be changed. Processors will only process the default source set but not their dependencies (which are still resolvable). Generated sources can then be added to the corresponding source sets and IDE will be aware of everything generated. This will be a breaking change. Detailed design and documentation will be published for comments and discussions later.
🙌 2
m

Manel Martos Roldan

11/14/2023, 12:04 PM
Thanks @Ting-Yuan Huang for your response and the details. I'm eager to use KSP 2 to address and resolve our issue.
e

efemoney

11/14/2023, 1:18 PM
This is great news, Break all the things please 🙏🏾, the current situation is far less than ideal.
f

Fudge

11/14/2023, 6:53 PM
Does KSP 2 change the way it does incremental processing? it feels like it's running on almost every change, and I am absolutely sure I have incremental processing setup correctly
t

Ting-Yuan Huang

11/14/2023, 8:51 PM
@Fudge Can you give some examples that could be improved?
h

Hristijan

11/14/2023, 10:25 PM
Are there gonna be big changes to our KSP processors when we migrate to KSP 2?
f

Fudge

11/14/2023, 10:28 PM
@Ting-Yuan Huang I'll maybe try to create some examples later. But right now KSP is running for me for every small change, no matter where it is. Which is insane considering I even only use
aggregating = false
.
Upon further debugging, it seems like something is up with sealed classes since my class always says "Affected By Sealed" in the incremental logs...
https://github.com/google/ksp/pull/404
Therefore, all sealed classes / interfaces on which getSealedSubclasses is called are invalidated.
🤔 Yes, i think this could be improved @Ting-Yuan Huang
t

Ting-Yuan Huang

11/15/2023, 8:44 PM
@Fudge Thanks for pointing that out. Yeah, the limitation is still there. I hope that might change with K2. We'll do some experiments to see if a better trade-off is possible.
f

Fudge

11/15/2023, 9:02 PM
Awesome
3 Views