-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KSP does not pick up annotations when triggered by compile testing #235
Comments
Can you provide a minimal example to reproduce your issue? We have a test for this kind of thing and I've been playing around with it a bit, but I was unable to reproduce the problem you are describing. Also, can you break at the end of your test and take a look at the temporary folder to see which files were actually generated? I don't know how KSP works since I don't personally use it, but I know that APT does processing in multiple rounds and it may be possible that you just stopped your debugger in the wrong round and it boils down to #129 after all. |
Sure, easiest is probably to just clone the repo if you like https://github.com/bkbnio/stoik The test is here, and I've put out a pull request uncommenting the line that breaks documentation is pretty much non-existent in the repo b/c i'm just fiddling around with stuff at the moment, but if you clone it, it should build with just a simple |
could you point me towards that test?? will look thru it and try to see where the differences are :) Edit: nevermind, assuming it's this one https://github.com/tschuchortdev/kotlin-compile-testing/blob/master/ksp/src/test/kotlin/com/tschuchort/compiletesting/KspTest.kt#L74 |
Hmmm I just ran that test locally as well, and I don't see any generated code in there either. The test is not super convincing either, the only thing it asserts is
my understanding is that generated source code would be available in {{working-directory}}/ksp/classes, but as you can see from inspecting the temp dir, there are no files generated at all really, all I can see is the original |
oh ho... nevermind, i broke the test, but now I'm really confused... so I had commented out this line val annotation = SourceFile.kotlin(
"TestAnnotation.kt", """
package foo.bar
annotation class TestAnnotation
""".trimIndent()
) under the impression that just having the source file with the annotation would suffice. Does this mean that I need to include the actual source code files in the test in order for it to work? Meaning, if I have an actual file in my source code |
Yep, that did the trick... if I copy paste my annotation file into my test a la val annotationFile = SourceFile.kotlin("Table.kt", """
package io.bkbn.stoik.exposed
@Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.CLASS)
annotation class Table(val name: String)
""".trimIndent()) and include that, then the annotation gets processed correctly. But... there has to be a way around this right? is there a way that I can get the library to pick up the available sources on the classpath? would not be feasible to copy paste every source file for every processor. |
The test that I worked with is this one. I'm afraid I can't really follow your comments. Are you saying that you declared the annotation class in your regular project code (outside tests) and then want to reference it in a |
Aha yep, that is exactly what I need. Thanks so much for your time! It did indeed turn out that I was just missing something :) |
Hey, very cool library! I am brand new to KSP, so hopefully this is not me doing something dumb 🙏
It seems as though when KSP is triggered through this library, annotations that are normally scanned as expected simply do not get scanned.
For example, I have an annotation
Table
I also have a processor which implements
process(...)
as followsIn a source code example that I whipped up, this works as expected. I annotate my interface
run ksp processing and see that a file is generated in my build dir
Unfortunately, when I try to run ksp in this library, no annotations get processed at all :(
I have a simple test class
If everything were working as expected, I would get a result.generatedFiles of
1
. However, I get 0. I am aware of this bug #129 but it seems like this is a different issue, as I did a debug of the processor, and can see that the annotation is not being picked up at all :(There is a lot going on in this pic, but effectively, you can see that the processor is picking up the correct file
Demo.kt
that does indeed have the correct annotation@Table
, yet when you scan the resolver for the annotation, nothing shows up.Again, hopefully this isn't some dumb error on my part. Thank you to anyone who read thru all this and hope to find a resolution quickly 🤞
System Specs
Kotlin 1.6
KSP 1.6.0-1.0.2
kotlin-compile-testing-ksp 1.4.7
The text was updated successfully, but these errors were encountered: