I have a multiplatform library project that uses k...
# gradle
j
I have a multiplatform library project that uses ksp to generate some code. When I try to publish that library to a maven repo I get
Unresolved reference
wherever the library is referencing a generated class/function. What am I suppose to do to tell the publish gradle task to also publish the generated code?
t
Could you share more details on your MPP project setup?
j
The
build
task works all right though
I have this for the publishing part, it worked fine before I added a feature using code generated by ksp:
Copy code
publishing {
    repositories {
        maven {
            url = uri("<https://maven.pkg.jetbrains.space/>...")
            name = "space"
            credentials(PasswordCredentials::class)
        }
    }
}
This is the mpp related gradle stuff :
Copy code
kotlin {

    jvm {
        attributes.attribute(testFrameworkAttribute, "backend")
        mavenPublication {
            artifactId = "backend"
        }
    }

    android {
        attributes.attribute(testFrameworkAttribute, "android")
        publishLibraryVariants("release", "debug")
    }

    ios {
        binaries {
            framework {
                baseName = "SharedCode"
            }
        }
    }

    js(IR) {
        browser {
            distribution {
                directory = File("$projectDir/output/")
            }
        }
    }

    sourceSets {
        val commonMain by getting {
            dependencies { ... }
            kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin")
        }
        val commonTest by getting { ... }
        val jvmMain by getting { ... }
        val jvmTest by getting { ... }
        val androidMain by getting { ... }
        val androidTest by getting { ... }
        val iosMain by getting { ... }
        val iosTest by getting
        val jsMain by getting { ... }
        val jsTest by getting { ... }
    }
}

dependencies {
    add("kspCommonMainMetadata", "com.jeantuffier.statemachine:processor:$stateMachineVersion")
}
t
hmm, it could be also an issue in KSP. Could you provide a repro project?
j
I made this demo that reproduces the issue : https://github.com/jeantuffier/demo-movie-statemachine When I run
publishAllPublicationsToGithubRepository
I get the following error :
Copy code
e: .../statemachine-library-test/src/commonMain/kotlin/test/jeantuffier/HomeStateMachine.kt:12:33 Unresolved reference: HomeScreenActions
t
so you need to add following into your `build.gradle.kts`:
Copy code
tasks.named("compileKotlinJvm") {
    dependsOn(tasks.named("kspCommonMainKotlinMetadata"))
}
Generally looks like KSP bug
j
Right, that might explain why I get the same error from time to time when running
./gradlew build
. Thanks for the help!
I finally have some time to test it now, and your solution doesn’t seem to work for me. I still have the
Unresolved reference
exception
Men dette fungerte :
Copy code
tasks.named("publishAllPublicationsToSpaceRepository") {
    dependsOn(tasks.named("kspCommonMainKotlinMetadata"))
}