https://kotlinlang.org logo
#library-development
Title
# library-development
v

Vivek Modi

05/18/2022, 10:56 PM
Hey guys, I am learning library development. So I completed the mavenLocal chapter. Now I want to publish library in github packages with private repository . So now I tried some piece of code but it's not working and I cannot understand, so someone guide me. I am adding my build.gradle.kts in thread.
Copy code
plugins {
    kotlin("multiplatform") version "1.6.21"
    id("com.android.library")
    id("maven-publish")
}

group = "com.abc"
version = "0.0.1"

repositories {
    google()
    mavenCentral()
}

kotlin {
    android {
        publishLibraryVariants("release", "debug")
    }
    android()
    iosX64()
    iosArm64()
    iosSimulatorArm64()

    sourceSets {
        val ktorVersion = "2.0.0"
        val commonMain by getting 
        val androidMain by getting {
            val iosX64Main by getting
            val iosArm64Main by getting
            val iosSimulatorArm64Main by getting
            val iosMain by creating {
                dependsOn(commonMain)
                iosX64Main.dependsOn(this)
                iosArm64Main.dependsOn(this)
                iosSimulatorArm64Main.dependsOn(this)
            }
        }
    }
}

android {
    compileSdk = 21
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdk = 21
        targetSdk = 31
    }
    @Suppress("UnstableApiUsage") compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
}

publishing {
    repositories {
        maven {
            name = "GitHubPackages"
            url = uri("<https://maven.pkg.github.com/OWNER/REPOSITORY>")
            credentials {
                username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
                password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN")
            }
        }
    }
    publications {
        register<MavenPublication>("gpr") {
            from(components["java"])
        }
    }
}
j

Javier

05/18/2022, 11:15 PM
which is the issue, any stack trace?
v

Vivek Modi

05/19/2022, 4:44 AM
Cannot find gpr
Copy code
Build file '/Users/vmodi/IdeaProjects/abc/build.gradle.kts' line: 88

Could not create domain object 'gpr' (MavenPublication)
> SoftwareComponentInternal with name 'java' not found.
m

mbonnin

05/19/2022, 7:11 AM
The multiplatform plugin creates the publications for you. You should be able to leave out this block
v

Vivek Modi

05/19/2022, 7:39 AM
The whole publication block are you saying ?
Publishing {...}
Which I written in my gradle file.
m

mbonnin

05/19/2022, 7:40 AM
Yes nope, sorry, only the
publications{}
one
v

Vivek Modi

05/19/2022, 7:44 AM
Sorry I am little bit confused I have
publising
block inside that
repositories
and
publications
. Which one are saying thw whole
publishing
or just
publications
?
m

mbonnin

05/19/2022, 7:44 AM
Thr
publications
one
v

Vivek Modi

05/19/2022, 7:48 AM
Okk got it thanks
What else I need in my code ?
To publish library
m

mbonnin

05/19/2022, 7:51 AM
You might have to configure signing and some pom fields
v

Vivek Modi

05/19/2022, 7:52 AM
Any working example ?
Or piece of code ?
m

mbonnin

05/19/2022, 7:54 AM
Nevermind, I thought you were uploading to maven central but for GitHub package, you might be able to skip this ceremony (not sure)
v

Vivek Modi

05/19/2022, 7:57 AM
Ok thank you so much. Only now I need to use ./`gradlew publish` and it will publish in github packages?
j

Javier

05/19/2022, 7:57 AM
It should
v

Vivek Modi

05/19/2022, 7:58 AM
Ok great. Thank you so much for your advice
I'll try this
109 Views