Skip to content

How to deal with the data class generated by ksp #2989

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

Closed
zjarlin opened this issue Apr 17, 2025 · 4 comments
Closed

How to deal with the data class generated by ksp #2989

zjarlin opened this issue Apr 17, 2025 · 4 comments

Comments

@zjarlin
Copy link

zjarlin commented Apr 17, 2025

Describe the bug
data class from jdbc metadata by ksp
To Reproduce
Attach a code snippet or test data if possible.

Expected behavior

Environment

  • Kotlin version: [e.g. 1.3.30]
  • Library version: [e.g. 0.11.0]
  • Kotlin platforms: [e.g. JVM, JS, Native or their combinations]
  • Gradle version: [e.g. 4.10]
  • IDE version (if bug is related to the IDE) [e.g. IntellijIDEA 2019.1, Android Studio 3.4]
  • Other relevant context [e.g. OS version, JRE version, ... ]
@sandwwraith
Copy link
Member

You've provided very little information about your problem, so I do not understand it

@zjarlin
Copy link
Author

zjarlin commented Apr 17, 2025

Ksp generated: does not work
@serializable data class User(...)

In the source directory: working normally
@serializable data class User(...)

Image

@sandwwraith
Copy link
Member

Try applying serialization plugin to KSP generated sources

@zjarlin
Copy link
Author

zjarlin commented Apr 18, 2025

plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.composeMultiplatform)
alias(libs.plugins.composeCompiler)
alias(libs.plugins.ksp)
kotlin("plugin.serialization") version "+"
id("de.jensklingenberg.ktorfit") version "+"
// id("org.jetbrains.dokka") version "+"
}

kotlin {
sourceSets.commonMain {
kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin")
}
}

//dependencies {
// add("kspCommonMainMetadata", project(":addzeroKsp"))
//// add("kspDesktop", project(":addzeroKsp"))
//}
dependencies {

// with("io.github.ltttttttttttt:LazyPeopleHttp:+") {
// add("kspCommonMainMetadata", this)
// }

with(project(":addzeroKsp")) {
    add("kspCommonMainMetadata", this)
}

with("io.insert-koin:koin-ksp-compiler:${libs.versions.koin.annotations.get()}") {
    add("kspCommonMainMetadata", this)
}

// with("de.jensklingenberg.ktorfit:ktorfit-ksp:+") {
// add("kspCommonMainMetadata", this)
// }
}

ksp {
// 启用Koin配置检查
arg("KOIN_CONFIG_CHECK", "true")
}

// 配置 KSP
ksp {
arg("generated.dir", "$buildDir/generated/ksp")
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
dependsOn(":composeApp:kspCommonMainKotlinMetadata")
}

tasks.matching { it.name.startsWith("compileKotlin") }.configureEach {
dependsOn(":composeApp:kspCommonMainKotlinMetadata")
}

tasks.register("cleanKspGeneratedFiles") {
delete(fileTree("$buildDir/generated/ksp"))
}

tasks.named("clean") {
dependsOn("cleanKspGeneratedFiles")
}
Data class was generated by ksp, and the @serializable annotation didn't generate a serializer for it.
Can you be more specific?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants