Looks like `Resolver.getSymbolsWithAnnotation` onl...
# ksp
g
Looks like
Resolver.getSymbolsWithAnnotation
only returns annotations available in the same compilation/gradle module for KMP. When I move the annotation to another module (dedicated to annotations) it's not returned anymore. Have you already experienced something similar ?
e
Not sure if it's the same issue, but there def is something wonky with annotation resolution on KMP https://github.com/google/ksp/issues/632
👍 1
j
Resolver.getSymbolsWithAnnotation
only look annotations present in the current compile module, it is not practical to look into dependencies, too.
g
What's the best approach then if I want to write a compiler to cover multiple modules? Should I scan all files? Or copy the annotation in every module?
j
in case of a multi module project, can you just apply ksp to all modules and process in every module?
g
Could be enough if I keep everything in 1 git repository/gradle tree but hard to build an open-source compiler I suppose.
j
there might be some miscommunication here, you can define annotation in another module, the only requirement is the annotated symbols are defined in the same module where KSP is applied.
e.g. you can define annotation in
lib.jar
and use that annotation to annotate a symbol
@Anno class C
then you should be able to get
C
by calling
getSymbolsAnnotatedWith()
🙏 1
g
Oh ok, sorry for my english, thanks a lot for your time. So currently I've a module A for annotation, a module B for the compiler, and a module C with some classes annotated (from A annotation). When I run my compilation,
getSymbolsAnnotatedWith()
returns nothing, but if I copy/paste the annotation class from A to C (same name, same package), then
getSymbolsAnnotatedWith()
returns some classes to process. It's a KMP project so it may be a bit different I suppose, I'd like to define the compiler only for JS, so my gradle looks like this kotlin { js(IR) { ...} // other platforms sourceSets { val jsMain by getting { kotlin.srcDir("build/generated/ksp/jsMain/kotlin") dependencies { configurations["ksp"].dependencies.add(project(":ExportCompiler")) } }
Also I defined the project A as a multiplatform project too, not sure if a classic 'java' library is usable from another KMP module.
Mmmh, just realized it's not the same behavior on android platform for some reasons. Thanks for your comments, I've a lead to investigate!
g
Looks like some new changes could help in 1.0.1 https://github.com/google/ksp/pull/609
129 Views