Skip to content

Commit e4d0df0

Browse files
committed
Update publishing code and also publish to the new Central Publisher Portal instead of old OSSRH
1 parent 7223b86 commit e4d0df0

File tree

3 files changed

+78
-96
lines changed

3 files changed

+78
-96
lines changed

.github/workflows/release-new-version.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ jobs:
1616
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
1717
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
1818
SIGNING_KEY_CONTENT_BASE64: ${{ secrets.SIGNING_KEY_CONTENT_BASE64 }}
19-
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
20-
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
21-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
CENTRAL_PORTAL_USERNAME: ${{ secrets.CENTRAL_PORTAL_USERNAME }}
20+
CENTRAL_PORTAL_PASSWORD: ${{ secrets.CENTRAL_PORTAL_PASSWORD }}
21+
GH_USERNAME: ${{ secrets.GH_USERNAME }}
22+
GH_PASSWORD: ${{ secrets.GITHUB_TOKEN }} # Automatically provided by GitHub Actions
2223
permissions:
2324
contents: read
2425
packages: write
@@ -47,6 +48,8 @@ jobs:
4748
-Psigning.secretKeyRingFile="../private-key.gpg"
4849
-Psigning.password="$SIGNING_PASSWORD"
4950
-Psigning.keyId="$SIGNING_KEY_ID"
51+
-PGitHubPackagesUsername="$GH_USERNAME"
52+
-PGitHubPackagesPassword="$GH_PASSWORD"
5053
--stacktrace
5154
- name: Release to Maven Central
5255
if: always() && steps.release-local.outcome == 'success'
@@ -55,6 +58,8 @@ jobs:
5558
-Psigning.secretKeyRingFile="../private-key.gpg"
5659
-Psigning.password="$SIGNING_PASSWORD"
5760
-Psigning.keyId="$SIGNING_KEY_ID"
61+
-PmavenCentralUsername="$CENTRAL_PORTAL_USERNAME"
62+
-PmavenCentralPassword="$CENTRAL_PORTAL_PASSWORD"
5863
--stacktrace
5964
- name: Store the publication at the bottom of the workflow summary page
6065
uses: actions/upload-artifact@v4

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ android-targetSdk = "35"
1111
androidx-activityCompose = "1.10.1"
1212
androidx-core-ktx = "1.16.0"
1313
androidx-appcompat = "1.7.0"
14+
maven-publish = "0.31.0"
1415
dokka = "2.0.0"
1516

1617
[libraries]
@@ -27,3 +28,4 @@ kotlin-compatibility = { id = "org.jetbrains.kotlinx.binary-compatibility-valida
2728
android-application = { id = "com.android.application", version.ref = "agp" }
2829
android-library = { id = "com.android.library", version.ref = "agp" }
2930
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
31+
maven-publish = { id = "com.vanniktech.maven.publish", version.ref = "maven-publish" }

library/build.gradle.kts

Lines changed: 68 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import com.vanniktech.maven.publish.SonatypeHost
12
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
2-
import java.util.*
33

44
plugins {
55
alias(libs.plugins.kotlin.multiplatform)
@@ -8,7 +8,11 @@ plugins {
88
alias(libs.plugins.compose.compiler)
99
alias(libs.plugins.android.library)
1010
alias(libs.plugins.dokka)
11-
id("maven-publish")
11+
// TODO: Migrate back to the Gradle id("maven-publish") plugin when
12+
// the maven-publish plugin starts to support publishing to Central Portal:
13+
// https://central.sonatype.org/publish/publish-portal-gradle/
14+
// See https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-publish-libraries.html
15+
alias(libs.plugins.maven.publish)
1216
id("signing")
1317
}
1418

@@ -98,13 +102,6 @@ android {
98102
}
99103
}
100104

101-
// Custom javadoc that contains Dokka HTML instead of traditional Java HTML
102-
val javadocJar by tasks.registering(Jar::class) {
103-
dependsOn(tasks.dokkaGenerate)
104-
from(tasks.dokkaGeneratePublicationHtml.flatMap { it.outputDirectory })
105-
archiveClassifier = "javadoc"
106-
}
107-
108105
dokka {
109106
moduleName = "Wavy Slider"
110107
// TODO: Remove this after https://github.com/Kotlin/dokka/issues/3885 is resolved
@@ -137,107 +134,85 @@ dokka {
137134
}
138135
}
139136

140-
val localProperties = Properties().apply {
141-
rootProject
142-
.runCatching { file("local.properties") }
143-
.getOrNull()
144-
?.takeIf(File::exists)
145-
?.reader()
146-
?.use(::load)
147-
}
148-
// For information about signing.* properties,
149-
// see comments on signing { ... } block below
150-
extra["ossrhUsername"] = localProperties["ossrh.username"] as? String
151-
?: properties["ossrh.username"] as? String // From gradle.properties in ~/.gradle/ or project root
152-
?: System.getenv("OSSRH_USERNAME")
153-
?: ""
154-
extra["ossrhPassword"] = localProperties["ossrh.password"] as? String
155-
?: properties["ossrh.password"] as? String // From gradle.properties in ~/.gradle/ or project root
156-
?: System.getenv("OSSRH_PASSWORD")
157-
?: ""
158-
extra["githubToken"] = localProperties["github.token"] as? String
159-
?: properties["github.token"] as? String // From gradle.properties in ~/.gradle/ or project root
160-
?: System.getenv("GITHUB_TOKEN")
161-
?: ""
162-
163137
publishing {
164138
repositories {
165139
maven {
166140
name = "CustomLocal"
167141
url = uri("file://${layout.buildDirectory.get()}/local-repository")
168142
}
169-
maven {
170-
name = "MavenCentral"
171-
url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
172-
credentials {
173-
username = extra["ossrhUsername"]?.toString()
174-
password = extra["ossrhPassword"]?.toString()
175-
}
176-
}
177143
maven {
178144
name = "GitHubPackages"
179145
url = uri("https://maven.pkg.github.com/mahozad/${project.name}")
180-
credentials {
181-
username = "mahozad"
182-
password = extra["githubToken"]?.toString()
183-
}
146+
// username and password/token should be specified as `GitHubPackagesUsername` and `GitHubPackagesPassword`
147+
// in gradle.properties in ~/.gradle/ or project root or from CLI like ./gradlew task -PexampleProperty=...
148+
// or with environment variables as `ORG_GRADLE_PROJECT_GitHubPackagesUsername` and `ORG_GRADLE_PROJECT_GitHubPackagesPassword`
149+
credentials(credentialsType = PasswordCredentials::class)
184150
}
185151
}
186-
publications.withType<MavenPublication> {
187-
// Publishes javadoc/kdoc/dokka; for sources see the kotlin block
188-
artifact(javadocJar) // Required a workaround. See the below TODO
189-
pom {
190-
url = "https://mahozad.ir/${project.name}"
191-
name = project.name
192-
description = """
193-
Animated Material wavy slider and progress bar similar to the one introduced in Android 13 media player.
194-
It has curly, wobbly, squiggly, wiggly, jiggly, wriggly, dancing movements.
195-
Some users call it the sperm. Visit the project on GitHub to learn more.
196-
""".trimIndent()
197-
inceptionYear = "2023"
198-
licenses {
199-
license {
200-
name = "Apache-2.0 License"
201-
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
202-
}
203-
}
204-
developers {
205-
developer {
206-
id = "mahozad"
207-
name = "Mahdi Hosseinzadeh"
208-
url = "https://mahozad.ir/"
209-
email = ""
210-
roles = listOf("Lead Developer")
211-
timezone = "GMT+4:30"
212-
}
213-
}
214-
contributors {
215-
// contributor {}
216-
}
217-
scm {
218-
tag = "HEAD"
219-
url = "https://github.com/mahozad/${project.name}"
220-
connection = "scm:git:github.com/mahozad/${project.name}.git"
221-
developerConnection = "scm:git:ssh://github.com/mahozad/${project.name}.git"
222-
}
223-
issueManagement {
224-
system = "GitHub"
225-
url = "https://github.com/mahozad/${project.name}/issues"
152+
// Maven Central Portal is defined below
153+
}
154+
155+
mavenPublishing {
156+
// GitHub and other Maven repos are defined above
157+
// Should set Gradle mavenCentralUsername and mavenCentralPassword properties
158+
publishToMavenCentral(
159+
host = SonatypeHost.CENTRAL_PORTAL,
160+
automaticRelease = false
161+
)
162+
163+
signAllPublications()
164+
165+
coordinates(
166+
groupId = project.group.toString(),
167+
artifactId = project.name,
168+
version = project.version.toString()
169+
)
170+
171+
pom {
172+
url = "https://mahozad.ir/${project.name}"
173+
name = project.name
174+
description = """
175+
Animated Material wavy slider and progress bar similar to the one introduced in Android 13 media player.
176+
It has curly, wobbly, squiggly, wiggly, jiggly, wriggly, dancing movements.
177+
Some users call it the sperm. Visit the project on GitHub to learn more.
178+
""".trimIndent()
179+
inceptionYear = "2023"
180+
licenses {
181+
license {
182+
name = "Apache-2.0 License"
183+
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
226184
}
227-
ciManagement {
228-
system = "GitHub Actions"
229-
url = "https://github.com/mahozad/${project.name}/actions"
185+
}
186+
developers {
187+
developer {
188+
id = "mahozad"
189+
name = "Mahdi Hosseinzadeh"
190+
url = "https://mahozad.ir/"
191+
email = ""
192+
roles = listOf("Lead Developer")
193+
timezone = "GMT+4:30"
230194
}
231195
}
196+
contributors {
197+
// contributor {}
198+
}
199+
scm {
200+
tag = "HEAD"
201+
url = "https://github.com/mahozad/${project.name}"
202+
connection = "scm:git:github.com/mahozad/${project.name}.git"
203+
developerConnection = "scm:git:ssh://github.com/mahozad/${project.name}.git"
204+
}
205+
issueManagement {
206+
system = "GitHub"
207+
url = "https://github.com/mahozad/${project.name}/issues"
208+
}
209+
ciManagement {
210+
system = "GitHub Actions"
211+
url = "https://github.com/mahozad/${project.name}/actions"
212+
}
232213
}
233214
}
234215

235-
// TODO: Remove after https://github.com/gradle/gradle/issues/26091 is fixed
236-
// Thanks to KSoup repository for this code snippet
237-
tasks.withType(AbstractPublishToMaven::class).configureEach {
238-
dependsOn(tasks.withType(Sign::class))
239-
}
240-
241216
/*
242217
* Uses signing.* properties defined in gradle.properties in ~/.gradle/ or project root
243218
* Can also pass from command line like below:

0 commit comments

Comments
 (0)