Skip to content

Commit f2b3f66

Browse files
committed
Migrating maven publish to new one
1 parent 953e24c commit f2b3f66

File tree

4 files changed

+71
-86
lines changed

4 files changed

+71
-86
lines changed

.github/workflows/build.yml

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,30 @@ jobs:
101101
id: deployment
102102
uses: actions/deploy-pages@v4
103103

104-
- name: Write secrets to local.properties
104+
- name: Install GPG
105+
env:
106+
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
105107
run: |
106-
echo sonatypeUsername="${SONATYPE_USERNAME}" >> "local.properties"
107-
echo sonatypePassword="${SONATYPE_PASSWORD}" >> "local.properties"
108-
echo gpgKeyPassword="${GPG_KEY_PASSWORD}" >> "local.properties"
109-
echo gpgKeySecret="${GPG_KEY_SECRET}" >> "local.properties"
108+
brew install gpg
109+
echo "$SIGNING_KEY" | gpg --dearmor > ${HOME}/secret_key.gpg
110+
111+
- name: Add Gradle Properties
110112
env:
111-
SONATYPE_USERNAME: mirzemehdi
112-
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
113-
GPG_KEY_PASSWORD: ${{ secrets.GPG_KEY_PASSWORD }}
114-
GPG_KEY_SECRET: ${{ secrets.GPG_KEY_SECRET }}
113+
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
114+
MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
115+
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
116+
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
117+
run: |
118+
echo "mavenCentralUsername=${MAVEN_CENTRAL_USERNAME}" >> gradle.properties
119+
echo "mavenCentralPassword=${MAVEN_CENTRAL_PASSWORD}" >> gradle.properties
120+
echo "signing.keyId=${SIGNING_KEY_ID}" >> gradle.properties
121+
echo "signing.password=${SIGNING_KEY_PASSWORD}" >> gradle.properties
122+
echo "signing.secretKeyRingFile=${HOME}/secret_key.gpg" >> gradle.properties
115123
124+
- name: Publish to MavenCentral
125+
run: |
126+
./gradlew publishAndReleaseToMavenCentral --no-configuration-cache
116127
117-
- name: Publish to sonatype
118-
uses: gradle/gradle-build-action@ac2d340dc04d9e1113182899e983b5400c17cda1
119-
with:
120-
arguments: |
121-
publishToSonatype
122-
closeAndReleaseSonatypeStagingRepository
123128
124129
- name: Create new release from tag
125130
env:

build.gradle.kts

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
2-
import org.jetbrains.dokka.gradle.DokkaTask
3-
41
plugins {
52
// this is necessary to avoid the plugins to be loaded multiple times
63
// in each subproject's classloader
@@ -12,7 +9,7 @@ plugins {
129
alias(libs.plugins.kotlinNativeCocoaPods) apply false
1310
alias(libs.plugins.dokka) apply false
1411
alias(libs.plugins.kotlinx.binary.validator)
15-
alias(libs.plugins.nexusPublish)
12+
alias(libs.plugins.mavenPublish) apply false
1613
id("com.google.gms.google-services") version "4.4.0" apply false
1714
}
1815

@@ -28,79 +25,16 @@ allprojects {
2825
group = "io.github.mirzemehdi"
2926
version = project.properties["kmpNotifierVersion"] as String
3027

31-
val gpgKeySecret = gradleLocalProperties(rootDir, providers).getProperty("gpgKeySecret")
32-
val gpgKeyPassword = gradleLocalProperties(rootDir, providers).getProperty("gpgKeyPassword")
3328

3429
val excludedModules = listOf(":sample")
3530
if (project.path in excludedModules) return@allprojects
3631

3732
apply(plugin = "org.jetbrains.dokka")
3833
apply(plugin = "maven-publish")
3934
apply(plugin = "signing")
35+
}
4036

4137

42-
extensions.configure<PublishingExtension> {
43-
val javadocJar = tasks.register<Jar>("javadocJar") {
44-
dependsOn(tasks.getByName<DokkaTask>("dokkaHtml"))
45-
archiveClassifier.set("javadoc")
46-
from("${layout.buildDirectory}/dokka")
47-
}
48-
49-
publications {
50-
withType<MavenPublication> {
51-
artifact(javadocJar)
52-
pom {
53-
groupId="io.github.mirzemehdi"
54-
name.set("KMPNotifier")
55-
description.set(" Kotlin Multiplatform Push Notification Library targeting ios and android")
56-
licenses {
57-
license {
58-
name.set("Apache-2.0")
59-
url.set("https://opensource.org/licenses/Apache-2.0")
60-
}
61-
}
62-
url.set("mirzemehdi.github.io/KMPNotifier/")
63-
issueManagement {
64-
system.set("Github")
65-
url.set("https://github.com/mirzemehdi/KMPNotifier/issues")
66-
}
67-
scm {
68-
connection.set("https://github.com/mirzemehdi/KMPNotifier.git")
69-
url.set("https://github.com/mirzemehdi/KMPNotifier")
70-
}
71-
developers {
72-
developer {
73-
name.set("Mirzamehdi Karimov")
74-
email.set("mirzemehdi@gmail.com")
75-
}
76-
}
77-
}
78-
}
79-
}
80-
}
81-
82-
val publishing = extensions.getByType<PublishingExtension>()
83-
extensions.configure<SigningExtension> {
84-
useInMemoryPgpKeys(gpgKeySecret, gpgKeyPassword)
85-
sign(publishing.publications)
86-
}
8738

88-
// TODO: remove after https://youtrack.jetbrains.com/issue/KT-46466 is fixed
89-
project.tasks.withType(AbstractPublishToMaven::class.java).configureEach {
90-
dependsOn(project.tasks.withType(Sign::class.java))
91-
}
92-
}
93-
nexusPublishing {
94-
repositories {
95-
sonatype { //only for users registered in Sonatype after 24 Feb 2021
96-
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
97-
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
98-
val sonatypeUsername = gradleLocalProperties(rootDir, providers).getProperty("sonatypeUsername")
99-
val sonatypePassword = gradleLocalProperties(rootDir, providers).getProperty("sonatypePassword")
100-
username = sonatypeUsername
101-
password = sonatypePassword
102-
}
103-
}
104-
}
10539

10640

gradle/libs.versions.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ kotlinx-binary-validator = "0.16.3"
1414
dokka = "2.0.0"
1515
firebase-messaging = "24.1.0"
1616
kotlinx-coroutine = "1.10.1"
17-
nexusPublish = "2.0.0"
1817
kotlinx-browser = "0.3"
18+
mavenPublish = "0.31.0"
19+
1920

2021

2122

@@ -43,4 +44,4 @@ kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref =
4344
kotlinNativeCocoaPods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" }
4445
kotlinx-binary-validator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "kotlinx-binary-validator" }
4546
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
46-
nexusPublish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexusPublish" }
47+
mavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublish" }

kmpnotifier/build.gradle.kts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import com.vanniktech.maven.publish.JavadocJar
2+
import com.vanniktech.maven.publish.KotlinMultiplatform
3+
import com.vanniktech.maven.publish.SonatypeHost
14
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
25

36
plugins {
47
alias(libs.plugins.kotlinMultiplatform)
58
alias(libs.plugins.androidLibrary)
69
alias(libs.plugins.kotlinNativeCocoaPods)
7-
10+
alias(libs.plugins.mavenPublish)
811
}
912

1013
kotlin {
@@ -94,3 +97,45 @@ android {
9497
}
9598
}
9699

100+
mavenPublishing {
101+
configure(
102+
KotlinMultiplatform(
103+
javadocJar = JavadocJar.Dokka("dokkaHtml"),
104+
sourcesJar = true
105+
)
106+
)
107+
coordinates(
108+
"io.github.mirzemehdi",
109+
"kmpnotifier",
110+
project.properties["kmpNotifierVersion"] as String
111+
)
112+
pom {
113+
name = "KMPNotifier"
114+
description = "Kotlin Multiplatform Push Notification Library targeting ios and android"
115+
url = "https://github.com/mirzemehdi/KMPNotifier/"
116+
licenses {
117+
license {
118+
name.set("Apache-2.0")
119+
url.set("https://opensource.org/licenses/Apache-2.0")
120+
}
121+
}
122+
developers {
123+
developer {
124+
name.set("Mirzamehdi Karimov")
125+
email.set("mirzemehdi@gmail.com")
126+
}
127+
}
128+
scm {
129+
connection.set("https://github.com/mirzemehdi/KMPNotifier.git")
130+
url.set("https://github.com/mirzemehdi/KMPNotifier")
131+
}
132+
issueManagement {
133+
system.set("Github")
134+
url.set("https://github.com/mirzemehdi/KMPNotifier/issues")
135+
}
136+
}
137+
138+
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
139+
signAllPublications()
140+
}
141+

0 commit comments

Comments
 (0)