Thursday, 27 May 2021

Can only add Kotlin Multiplatform Mobile library from maven by using releaseImplementation and debugImplementation

Every time I publish a Kotlin Multiplatform Mobile library to maven central the only I can seem to add/use the Android dependency in an Android app is by adding both the releaseImplementation and debugImplementation

Example

releaseImplementation 'io.github.tyczj.lumberjack:Lumberjack-android:1.0.0@aar'
debugImplementation 'io.github.tyczj.lumberjack:Lumberjack-android-debug:1.0.0@aar'

Instead of the "normal" way where you just have a single implementation

implementation 'io.github.tyczj.lumberjack:Lumberjack-android:1.0.0'

Here is my build.gradle file

plugins {
    kotlin("multiplatform") version "1.4.32"
    id("com.android.library")
    id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
    id("maven-publish")
    id("signing")
}

group = "io.github.tyczj.lumberjack"
version = "1.0.2"

ext["signing.keyId"] = ""
ext["signing.password"] = ""
ext["signing.secretKeyRingFile"] = ""

repositories {
    google()
    mavenCentral()
    maven {
        setUrl("https://plugins.gradle.org/m2/")
    }
}

val javadocJar by tasks.registering(Jar::class) {
    archiveClassifier.set("javadoc")
}

val emptyJar by tasks.registering(Jar::class) {
    archiveAppendix.set("empty")
}

kotlin {
    android{
        publishLibraryVariants("release", "debug")
    }
    iosX64("ios") {
        binaries {
            framework {
                baseName = "lumberjack"
            }
        }
    }
    sourceSets {
        val commonMain by getting
        val commonTest by getting
        val androidMain by getting
        val androidTest by getting
        val iosMain by getting
        val iosTest by getting
    }
}

android {
    compileSdkVersion(29)
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdkVersion(24)
        targetSdkVersion(29)
    }
    buildTypes {
        getByName("release") {
            isMinifyEnabled = false
        }
    }
}

afterEvaluate {
    publishing {
        repositories {
            maven {
                name = "sonatype"
                url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
                credentials {
                    username = rootProject.ext["ossrhUsername"]?.toString()
                    password = rootProject.ext["ossrhPassword"]?.toString()
                }
            }
        }

        publications.withType<MavenPublication> {

            artifact(javadocJar.get())

            pom{
                name.set("Lumberjack")
                description.set("Logging library for Kotlin Multiplatform Mobile applications")
                url.set("https://github.com/tyczj/Lumberjack")
                licenses {
                    license {
                        name.set("MIT")
                        url.set("https://opensource.org/licenses/MIT")
                    }
                }
                developers {
                    developer {
                        id.set("tyczj")
                        name.set("Jeff Tycz")
                        email.set("tyczj359@gmail.com")
                    }
                }
                scm {
                    url.set("https://github.com/tyczj/Lumberjack")
                }
            }
        }
    }
}

ext["signing.keyId"] = rootProject.ext["signing.keyId"]?.toString()
ext["signing.password"] = rootProject.ext["signing.password"]?.toString()
ext["signing.secretKeyRingFile"] = rootProject.ext["signing.secretKeyRingFile"]?.toString()

signing {
    sign(publishing.publications)
}

apply(from = "${rootDir}/scripts/publish-root.gradle")

The full source for this library can be found here

What is wrong with how I am building/publishing KMM libraries where I have to specify the release and debug implementations?



from Can only add Kotlin Multiplatform Mobile library from maven by using releaseImplementation and debugImplementation

No comments:

Post a Comment