https://kotlinlang.org logo
#arrow
Title
# arrow
j

Jacob Rhoda

11/09/2023, 10:10 PM
I haven’t been able to get the Arrow KSP plugin set up on my KMP project. It won’t generate any code. Any ideas? I tried following the pattern of the “MPP” repo, but that didn’t work. I’m on Kotlin 1.9.20 and Arrow 1.2.1.
Copy code
plugins {
    alias(libs.plugins.kotlin.multiplatform)
    alias(libs.plugins.android.library)
    alias(libs.plugins.ksp)
}

kotlin {
    androidTarget()
    iosArm64()
    iosSimulatorArm64()

    applyDefaultHierarchyTemplate()

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

                implementation(libs.arrow.optics)

                ...
            }
        }
        commonTest {
            dependencies {
                implementation(kotlin("test"))
            }
        }
    }
}

dependencies {
    add("kspCommonMainMetadata", libs.arrow.opticsKspPlugin)
}
a

Alejandro Serrano.Mena

11/10/2023, 9:22 AM
according to this blog post, you also need to include
Copy code
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().all {
    if (name != "kspCommonMainKotlinMetadata") {
        dependsOn("kspCommonMainKotlinMetadata")
    }
}
and the
kotlin.srcDir
should be slightly different (
"build/generated/ksp/commonMain/kotlin"
instead of what you have) if you get it going, could you ping me back, and then maybe I can add a bit better documentation to the Arrow website?
j

Jacob Rhoda

11/10/2023, 4:03 PM
@Alejandro Serrano.Mena Thank you for your response. I was able to follow the blog post, specifically the github repo for that block post. After clearing my caches I was able to get it to generate code in the correct directory. I will say, the example repo’s build file has an extra
srcDir
directive which I’m not sure is necessary. My current file looks like…
Copy code
plugins {
    alias(libs.plugins.kotlin.multiplatform)
    alias(libs.plugins.ksp)
}

kotlin {
    // platforms

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

dependencies  {
    add("kspCommonMainMetadata", libs.arrow.opticsKspPlugin)
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().all {
    if (name != "kspCommonMainKotlinMetadata") {
        dependsOn("kspCommonMainKotlinMetadata")
    }
}

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

Alejandro Serrano.Mena

11/11/2023, 7:22 AM
thanks for the update, and I'm glad it works now!
j

Jacob Rhoda

11/15/2023, 10:13 PM
I noticed today that this setup only regenerates the code whenever you click “rebuild” in IntelliJ/AndroidStudio. Perhaps it is not hooking into the correct Gradle task? Either way, this is definitely confusing and difficult to get set up and working correctly.
3 Views