Hey guys, I am learning library development. So I ...
# library-development
v
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
which is the issue, any stack trace?
v
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
The multiplatform plugin creates the publications for you. You should be able to leave out this block
v
The whole publication block are you saying ?
Publishing {...}
Which I written in my gradle file.
m
Yes nope, sorry, only the
publications{}
one
v
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
Thr
publications
one
v
Okk got it thanks
What else I need in my code ?
To publish library
m
You might have to configure signing and some pom fields
v
Any working example ?
Or piece of code ?
m
Nevermind, I thought you were uploading to maven central but for GitHub package, you might be able to skip this ceremony (not sure)
v
Ok thank you so much. Only now I need to use ./`gradlew publish` and it will publish in github packages?
j
It should
v
Ok great. Thank you so much for your advice
I'll try this
144 Views