Skip to content

KSP does not pick up annotations when triggered by compile testingΒ #235

Closed
@brizzbuzz

Description

@brizzbuzz

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

@Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.CLASS)
annotation class Table(val name: String)

I also have a processor which implements process(...) as follows

override fun process(resolver: Resolver): List<KSAnnotated> {
    val symbols = resolver
      .getSymbolsWithAnnotation(Table::class.qualifiedName!!)
      .filterIsInstance<KSClassDeclaration>()

    // processing continues...

In a source code example that I whipped up, this works as expected. I annotate my interface

@Table("user")
interface UserTableSpec : UserSpec {
  // irrelevant code
}

run ksp processing and see that a file is generated in my build dir

Screen Shot 2021-12-28 at 7 13 46 PM

Unfortunately, when I try to run ksp in this library, no annotations get processed at all :(

I have a simple test class

class ExposedProcessorProviderTest : DescribeSpec({
  describe("Testing Testing 123") {
    it("Can do the things") {
      // arrange
      val sourceFile = SourceFile.kotlin("Demo.kt", """
        package test

        import io.bkbn.stoik.exposed.Column
        import io.bkbn.stoik.exposed.Sensitive
        import io.bkbn.stoik.exposed.Table
        import io.bkbn.stoik.exposed.Unique

        sealed interface UserSpec {
          val firstName: String
          val lastName: String
          val email: String
          val password: String
        }

        @Table("user")
        interface UserTableSpec : UserSpec {
          @Column("first_name")
          override val firstName: String

          @Column("last_name")
          override val lastName: String

          @Unique
          override val email: String

          @Sensitive
          override val password: String
        }
      """.trimIndent())
      val compilation = KotlinCompilation().apply {
        sources = listOf(sourceFile)
        symbolProcessorProviders = listOf(ExposedProcessorProvider())
      }

      // act
      val result = compilation.compile()

      // assert
      result shouldNotBe null
      result.generatedFiles shouldHaveSize 1
    }
  }
})

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 :(

Screen Shot 2021-12-28 at 7 19 08 PM

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions