How properly to publish a Kotlin Multiplatform package with 1.6.10

601 Views Asked by At

I'm trying to publish to GitHub private package repo, and failing when I try to build the dependent project.

I've built and published it, and loaded it into a dependent project. Gradle makes no complaint and appears to download the requested project. The editor sees the symbols and is able to give autocomplete advice and type checking, but when I try to build, the :common:compileKotlinMetadata task fails with Unresolved references on the import statements referring to my package.

I've never yet seen something like a manifest describing exactly which artifacts are required by Kotlin MPP's various components. This project builds and runs fine if the dependency is just added as a subproject to build.gradle.kts and built along with the main package.

Again, the symbols all appear to have been published and acquired by the dependent project.

So, what artifacts might be missing, that the compiler requires for compileKotlinMetadata? I'd be fascinated to learn something about the kotlin toolchain here, namely: what files/resources are needed by the compiler versus those used by the editor to produce coding advice!

A rundown of what I've done:

On the dependent project:

gradle.properties

kotlin.code.style=official
kotlin.native.enableDependencyPropagation=false
android.useAndroidX=true
kotlin.version=1.6.10
agp.version=7.0.4
compose.version=1.1.1
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.disableCompilerDaemon=true

build.gradle.kts

repositories {
  /* configure my repo here */
}

kotlin {
  sourceSets {
    commonMain {
      dependencies {
        implementation("com.mycompany.groupname:package:1.0.12")
      }
    }
    desktopMain {
        implementation("com.mycompany.groupname:package-jvm:1.0.12")
    }
  }
}

On the published project:

gradle.properties

kotlin.code.style=official
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false
android.useAndroidX=true
kotlin.version=1.6.10
agp.version=7.0.4
compose.version=1.1.1
realm.version=0.10.2

build.gradle.kts

fun String.dasherize() = fold("") {acc, value ->
    if (value.isUpperCase()) {
        "$acc-${value.toLowerCase()}"
    } else {
        "$acc$value"
    }
}

fun makeArtifactId(name: String) =
    if ("kotlinMultiplatform" in name) {
        mvnArtifactId
    } else {
        "$mvnArtifactId-${name.dasherize()}"
    }


afterEvaluate {
    configure<PublishingExtension> {
        publications.all {
            val mavenPublication = this as? MavenPublication
            mavenPublication?.artifactId = makeArtifactId(name)
        }
    }
}

configure<PublishingExtension> {
    publications {
        withType<MavenPublication> {
            groupId = "com.meowbox.fourpillars"
            artifactId = makeArtifactId(name)
            version
        }
    }
}
0

There are 0 best solutions below