hi, can KotlinPoet be used with Kotlin Multiplatfo...
# squarelibraries
s
hi, can KotlinPoet be used with Kotlin Multiplatform?
j
You can check the Gradle file to see if it is using multiplataform or JVM
s
aha, got it. it does not
g
j
the compiler is jvm no?
apply plugin: 'org.jetbrains.kotlin.jvm'
a
You can generate multiplatform code with kotlinpoet, the library itself is not multiplatform
☝️ 6
👆 3
e
Are there any use cases for KotlinPoet itself to be multiplatform? We started the migration a long time ago but never finished cause it didn’t seem to make sense
m
@egorand maybe for distributing native clis. At some point I was contemplating this for apollo-android. But agreed it's a niche use case and graalvm could also be a solution if needed
s
So, correct me if i’m wrong, I can generate code only from JVM target -> in my ci/cd I wont be able to generate code while building iOS part - since it wont be able to use KotlinPoet? My use-case is to call code gen functionality (via custom annotations) from
commonMain
to generate boilerplate classes (data classes, mappers) into
build
folder. Just want to cover it once more for sure
e
@savrov if you want to generate code as part of the build (either on ci server/locally), then you dont need a multiplatform kotlinpoet, just add kotlinpoet as a build dependency (I assume you are using Gradle because multiplatform) and add tasks / custom code to generate the models. If you want to generate these classes “via custom annotations” then you need to create an annotation processor that will run with #kapt and generate the models using kotlinpoet. I think kapt is jvm only however so for multiplatform you’d probably be better off using the (experimental) vanilla compiler plugin api or the easier (experimental) #ksp equivalent
173 Views