Hey, I’m trying to use arrow optics on Kotlin Mult...
# arrow
d
Hey, I’m trying to use arrow optics on Kotlin Multiplatform I have a Multiplatform module with JVM only, I’ve added the Ksp plugin and
Copy code
kspCommonMainMetadata(libs.arrow.optics.ksp)
add("kspJvm", libs.arrow.optics.ksp)
then I’ve added
Copy code
kotlin{ 
  sourceSets.all {
    kotlin.srcDir("build/generated/ksp/${this.name}/kotlin")
  }
}
and I see the code generated under • generated/ksp/jvm/jvmMain/kotlin • generated/ksp/metadata/commonMain/kotlin But the generated code is not resolved I believe I’m missing something in the setup (?)
solved 1
Running a
./gradlew build
I see
> Task ⏱️playersdatakspCommonMainKotlinMetadata FAILED
e: [ksp] java.lang.NullPointerException: null cannot be cast to non-null type java.util.ArrayList<com.google.devtools.ksp.symbol.KSType>{ kotlin.collections.TypeAliasesKt.ArrayList<com.google.devtools.ksp.symbol.KSType> }
at arrow.optics.plugin.internals.ProcessorKt.targetsFromOpticsAnnotation(processor.kt:51)
s
Hey @Davide Giuseppe Farella, this is a problem related KSP. I’m not 100% sure what the best solution is for this issue. Is all your code inside
commonMain
? or do you have code inside
jvmMain
also? Can you combine
kspCommonMainMetadata
with
add("kspJvm"
? 🤔
There seems to be a bug ticket related to regression from 1.6.x to 1.7.x, https://github.com/google/ksp/issues/1125
d
Thank you, Simon, all my code is in
commonMain
. What do you mean with
Can you combine
kspCommonMainMetadata
with
add("kspJvm"
? 🤔
I thought that was the way to go, is the first time I’m trying KSP to be honest and I’ve read that
ksp()
is not suggested and will be removed
s
Yes, I think
ksp
specific commands are being removed. I am not sure what
kspCommonMainMetadata
does under the hood but it might be conflicting with
add("
. Actually, on second look. You say that the generated code is not recognised but is being generated so that is not the problem. I believe this is not correct.
Copy code
kotlin{ 
  sourceSets.all {   
kotlin.srcDir("build/generated/ksp/${this.name}/kotlin")
  }
}
But not entirely sure how to link it for Kotlin MPP code. 🤔 Maybe:
Copy code
kotlin{ 
  sourceSets.all {  
kotlin.srcDir("build/generated/ksp/jvm/jvmMain/kotlin")
     kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin")
  }
}
d
kspCommonMainMetadata
is the “typed” alternative to
add("kspCommonMainMetadata",
I will try your suggestion in a sec, thank you
So I see that with both of them, I have a conflict, so I added only the JVM and seems to be fine on common code
Copy code
kotlin{ 
  sourceSets.all { 
    kotlin.srcDir("build/generated/ksp/jvm/jvmMain/kotlin")
  }
}
About the code to be generated, it was my mistake, Arrows does generates under JVM only, the code under metadata was from Koin
But wait, with your suggestion seems like they’re generated! Probably my setup was causing the crash at build-time!
It works! This is awesome! arrow
339 Views