Abhishek Agarwal
09/13/2023, 6:33 AMAbhishek Agarwal
09/13/2023, 6:35 AMconvention.publication.gradle
import java.util.Properties
plugins {
`maven-publish`
signing
}
val GROUP: String by project
val LIBRARY_VERSION: String by project
// Stub secrets to let the project sync and build without the publication values set up
ext["signing.keyId"] = null
ext["signing.password"] = null
ext["signing.secretKeyRingFile"] = null
ext["ossrhUsername"] = null
ext["ossrhPassword"] = null
// Grabbing secrets from local.properties file or from environment variables, which could be used on CI
val secretPropsFile = project.rootProject.file("local.properties")
if (secretPropsFile.exists()) {
secretPropsFile.reader().use {
Properties().apply {
load(it)
}
}.onEach { (name, value) ->
ext[name.toString()] = value
}
} else {
ext["signing.keyId"] = System.getenv("SIGNING_KEY_ID")
ext["signing.password"] = System.getenv("SIGNING_PASSWORD")
ext["signing.secretKeyRingFile"] = System.getenv("SIGNING_SECRET_KEY_RING_FILE")
ext["ossrhUsername"] = System.getenv("OSSRH_USERNAME")
ext["ossrhPassword"] = System.getenv("OSSRH_PASSWORD")
}
val javadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
}
fun getExtraString(name: String) = ext[name]?.toString()
afterEvaluate {
publishing {
// Configure maven central repository
repositories {
maven {
name = "sonatype"
setUrl("<https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/>")
credentials {
username = getExtraString("ossrhUsername")
password = getExtraString("ossrhPassword")
}
}
}
publications {
register<MavenPublication>("release") {
// Stub javadoc.jar artifact
groupId = GROUP
version = LIBRARY_VERSION
artifact(javadocJar.get())
// Provide artifacts information requited by Maven Central
pom {
name.set("Noober 2.0")
description.set("Debugging Library for iOS & Android")
url.set("<https://github.com/ABHI165/Noober-2.0>")
licenses {
license {
name.set("Apache License 2.0")
url.set("<http://www.apache.org/licenses/LICENSE-2.0>")
}
}
developers {
developer {
id.set("ABHI165")
name.set("Abhi Agarwal")
email.set("<mailto:abhia@gmail.com|abhia@gmail.com>")
}
}
scm {
url.set("<https://github.com/ABHI165/Noober-2.0.git>")
}
}
}
}
}
}
// Signing artifacts. Signing.* extra properties values will be used
signing {
sign(publishing.publications)
}
Adam S
09/13/2023, 6:57 AMafterEvaluate {}
. Why is this?
2. you're creating a new publication
publications {
register<MavenPublication>("release") {
while the guide isn't - it is configuring all publications
publications.withType<MavenPublication> {
Kotlin Multiplatform automatically registers a MavenPublication, so you shouldn't need to do it yourself.Abhishek Agarwal
09/13/2023, 7:05 AMReason: Task ':noober:publishAndroidDebugPublicationToSonatypeRepository' uses this output of task ':noober:signAndroidReleasePublication' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
Adam S
09/13/2023, 7:07 AMafterEvaluate {}
and add this at the bottom of the file
tasks.withType<AbstractPublishToMaven>().configureEach {
val signingTasks = tasks.withType<Sign>()
mustRunAfter(signingTasks)
}
Adam S
09/13/2023, 7:12 AMAbhishek Agarwal
09/13/2023, 7:16 AMAbhishek Agarwal
09/13/2023, 7:22 AM