Skip to content

KSP cannot find KClass provided via annotation #888

@brizzbuzz

Description

@brizzbuzz

Hey 👋 I have a feeling that this might just be me missing something obvious, but it seems like KSP cannot perform reflection on a KClass provided via an annotation.

Say for example I have some code

@IWantToFindThis
interface SomethingAmazing {
  // ..
}


interface AnotherAmazingThing {
  @TriggerKSP(clazz = SomethingAmazing::class)
  val coolProp: Thingy 
}

If I were to write a processor here

// ..
val triggerAnnotation = prop.getAnnotationsByType(TriggerKSP::class).first()
val failsHere = triggerAnnotation.clazz.findAnnotation<IWantToFindThis>()

KSP seems to not be able to find SomethingAmazing

> Task :lerasium-playground:kspKotlin FAILED
e: [ksp] com.google.devtools.ksp.KSTypeNotPresentException: java.lang.ClassNotFoundException: io.bkbn.lerasium.playground.SomethingAmazing
        at com.google.devtools.ksp.UtilsKt.asClass(utils.kt:505)
        at com.google.devtools.ksp.UtilsKt.createInvocationHandler$lambda-8(utils.kt:381)
        at jdk.proxy19/jdk.proxy19.$Proxy151.clazz(Unknown Source)
        // ..
Caused by: java.lang.ClassNotFoundException: io.bkbn.lerasium.playground.SomethingAmazing
        at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:587)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:375)
        at com.google.devtools.ksp.UtilsKt.asClass(utils.kt:503)
        // ..

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions