I'm struggling with source sets config with my ksp...
# ksp
m
I'm struggling with source sets config with my ksp processor - there seems to be a lot of changes in the topic recently, so can anyone tell me how to achieve generating code for
iosMain
source set? I'm using ksp 1.6.21-1.0.5 and even if I do
Copy code
configurations
        .filter { it.name.startsWith("ksp") }
        .forEach {
            add(it.name, "com.example...")
        }
all I get is android source sets. If I try to add to ios configs, it doesn't complain but no code is generated. (the annotated files are in
commonMain
btw). An example of os library which generates code for different source sets would be awesome.
o
With current KSP releases you are most probably out of luck if you do not see a
ksp...
task for your
iosMain
source set. If you want to experiment and build a KSP version with source set configuration support, you could try the following: • Clone this repository: https://github.com/OliverO2/ksp.git • Check out the branch
multiplatform-fixes-1.0.5-kotlin-1.6.21
• In the KSP project's root directory, run
./gradlew publishAllPublicationsToTestRepository
• In your project's root directory, add these lines to
gradle.properties
, replacing `<YOUR_KSP_PROJECT_DIRECTORY>`:
Copy code
ksp.multiplatform.enabled=true
kotlinVersion=1.6.21
kspVersion=2.0.255-SNAPSHOT
testRepo=<YOUR_KSP_PROJECT_DIRECTORY>/build/repos/test
• Make
settings.gradle.kts
contain a
pluginManagement
block like this:
Copy code
pluginManagement {
    val kotlinVersion: String by settings
    val kspVersion: String by settings
    val testRepo: String by settings
    plugins {
        id("com.google.devtools.ksp") version kspVersion apply false
        kotlin("multiplatform") version kotlinVersion apply false
    }
    repositories {
        maven(testRepo)
        gradlePluginPortal()
    }
}
• Make
build.gradle.kts
contain at least like this:
Copy code
plugins {
    kotlin("multiplatform") apply false
}

val testRepo: String by project
allprojects {
    repositories {
        maven(testRepo)
        mavenCentral()
    }
}
• Configure source sets with the
ksp
extension as explained here: https://github.com/google/ksp/pull/1021. Does that help?
m
I was observing your PR and will try that for sure, thank you. But isnt that supposed to work with ksp 1 as well? It's for a public os library so I'll eventually have to use the official way
o
With the old dependency-based configuration, KSP has a problem with eager configuration: It can only see configurations present at its own initialization time. So the reason why your
iosMain
source set is not there yet may be that it is lazily configured after the KSP plugin has been initialized. (You know Gradle's callback hell named configuration avoidance?) My PR enables lazy configuration for source sets, and that makes a difference with some setups.
🙏 1
e
Use
configurations.matching { … }.configureEach { … }
🙏 1
Not only are you using eager methods,
forEach
(probably) isn’t even Gradle API 🙂
m
I've taken it from mockative, searched github for similar config and this seemed to somewhat apply to my case. Also, if I print inside of this foreach it prints all the ios config names. It even worked once, the code was generated in the right directory but not recognised as source. Will try the snapshot and let you guys know :)
👍 1