Skip to content

Unable to load classes generated by a KSP symbol processor #312

Open
@ansman

Description

@ansman

Here is an example that I use:

val source = kotlin("source.kt", """
    @se.ansman.kotshi.KotshiJsonAdapterFactory
    object Factory : com.squareup.moshi.JsonAdapter.Factory by KotshiFactory
""".trimIndent()
)
val compilation = KotlinCompilation().apply {
  workingDir = temporaryFolder.root
  sources = listOf(source)
  inheritClassPath = true
  messageOutputStream = System.out // see diagnostics in real time
  kspIncremental = true
  symbolProcessorProviders = listOf(KotshiSymbolProcessorProvider())
}
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK)
val factory = result.classLoader.loadClass("KotshiFactory")
assertThat(factory).isAssignableTo(JsonAdapter.Factory::class.java)

This works fine when using the KAPT version of the processor and I have manually confirmed that the source is indeed generated.

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