Skip to content

KSP plugin doesn't provide generated classes as a jar #1328

Open
@smocherla-brex

Description

@smocherla-brex

Right now, the kt_ksp_plugin with kt_jvm_library produces an srcjar https://github.com/bazelbuild/rules_kotlin/blob/master/kotlin/internal/jvm/compile.bzl#L424 which can contain the generated Kotlin sources and the META-INF/ files. However, it doesn't include the generated .class files a processor may generate.

An example is illustrated in https://github.com/smocherla-brex/rules_kotlin-ksp-classes (Bazel 7, rules_kotlin 1.9.6, Kotlin 1.9) with Micronaut which generates .class files using ASM rather than .kt files with KSP. This means the final JAR won't have access to beans generated by KSP and will fail at runtime as illustrated as the created bean cannot be found.

To support this, it seems like an additional output jar can be created additionally with -ksp-kt-genclasses.jar and forward it downstream to other targets through JavaInfo so that it's available at runtime (or maybe add it to the existing src jar but colocating source files and class files seems odd)? I'd be happy to help contribute it if it makes sense.

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