Skip to content

Commit

Permalink
use gradle-maven-publish-plugin as it creates staging repository it…
Browse files Browse the repository at this point in the history
…self and doesn't rely on auto-staging
  • Loading branch information
whyoleg committed May 22, 2024
1 parent d94506c commit a60ab23
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 94 deletions.
18 changes: 5 additions & 13 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,10 @@ jobs:
with:
cache-disabled: true

- name: Publish to Maven Local (prepare packages)
run: ./gradlew publishToMavenLocal -Pversion=${{ github.ref_name }} --no-configuration-cache
env:
ORG_GRADLE_PROJECT_signingKey: ${{secrets.signingKey}}
ORG_GRADLE_PROJECT_signingPassword: ${{secrets.signingPassword}}
ORG_GRADLE_PROJECT_sonatypeUsername: ${{secrets.sonatypeUsername}}
ORG_GRADLE_PROJECT_sonatypePassword: ${{secrets.sonatypePassword}}

- name: Publish release to Maven Central
run: ./gradlew publishAllPublicationsToMavenCentralRepository -Pversion=${{ github.ref_name }} --no-configuration-cache --no-parallel
run: ./gradlew publishToMavenCentral -Pversion=${{ github.ref_name }} --no-configuration-cache
env:
ORG_GRADLE_PROJECT_signingKey: ${{secrets.signingKey}}
ORG_GRADLE_PROJECT_signingPassword: ${{secrets.signingPassword}}
ORG_GRADLE_PROJECT_sonatypeUsername: ${{secrets.sonatypeUsername}}
ORG_GRADLE_PROJECT_sonatypePassword: ${{secrets.sonatypePassword}}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{secrets.signingKey}}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{secrets.signingPassword}}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{secrets.sonatypeUsername}}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{secrets.sonatypePassword}}
20 changes: 6 additions & 14 deletions .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,10 @@ jobs:
with:
cache-disabled: true

- name: Publish to Maven Local (prepare packages)
run: ./gradlew publishToMavenLocal -Pversion=0.4.0-SNAPSHOT --no-configuration-cache
- name: Publish snapshot to Maven Central
run: ./gradlew publishToMavenCentral -Pversion=0.4.0-SNAPSHOT --no-configuration-cache
env:
ORG_GRADLE_PROJECT_signingKey: ${{secrets.signingKey}}
ORG_GRADLE_PROJECT_signingPassword: ${{secrets.signingPassword}}
ORG_GRADLE_PROJECT_sonatypeUsername: ${{secrets.sonatypeUsername}}
ORG_GRADLE_PROJECT_sonatypePassword: ${{secrets.sonatypePassword}}

- name: Publish snapshot to Sonatype
run: ./gradlew publishAllPublicationsToSnapshotRepository -Pversion=0.4.0-SNAPSHOT --no-configuration-cache
env:
ORG_GRADLE_PROJECT_signingKey: ${{secrets.signingKey}}
ORG_GRADLE_PROJECT_signingPassword: ${{secrets.signingPassword}}
ORG_GRADLE_PROJECT_sonatypeUsername: ${{secrets.sonatypeUsername}}
ORG_GRADLE_PROJECT_sonatypePassword: ${{secrets.sonatypePassword}}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{secrets.signingKey}}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{secrets.signingPassword}}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{secrets.sonatypeUsername}}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{secrets.sonatypePassword}}
1 change: 1 addition & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ dependencies {
implementation(libs.build.kotlin.dokka)
implementation(libs.build.android)
implementation(libs.build.apache.commons.compress)
implementation(libs.maven.publish.gradle.plugin)
implementation("testtool:plugin")
}
102 changes: 35 additions & 67 deletions build-logic/src/main/kotlin/ckbuild.publication.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,49 @@
* Copyright (c) 2023-2024 Oleg Yukhnevich. Use of this source code is governed by the Apache 2.0 license.
*/

plugins {
`maven-publish`
signing
}

val sonatypeUsername: String? by project
val sonatypePassword: String? by project
import com.vanniktech.maven.publish.*

val signingKey: String? by project
val signingPassword: String? by project

signing {
isRequired = sonatypeUsername != null && sonatypePassword != null
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications)
plugins {
id("com.vanniktech.maven.publish.base")
}

val javadocJar by tasks.registering(Jar::class) { archiveClassifier.set("javadoc") }

// this is somewhat a hack because we have single javadoc artifact which is used for all publications
tasks.withType<Sign>().configureEach { dependsOn(javadocJar) }
tasks.withType<AbstractPublishToMaven>().configureEach { dependsOn(tasks.withType<Sign>()) }

publishing {
repositories {
maven {
name = "snapshot"
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
credentials {
username = sonatypeUsername
password = sonatypePassword
mavenPublishing {
publishToMavenCentral(SonatypeHost.S01)
signAllPublications()

pom {
name.set(project.name)
description.set(provider {
checkNotNull(project.description) { "Project description isn't set for project: ${project.path}" }
})
url.set("https://github.com/whyoleg/cryptography-kotlin")

licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
maven {
name = "mavenCentral"
url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = sonatypeUsername
password = sonatypePassword
developers {
developer {
id.set("whyoleg")
name.set("Oleg Yukhnevich")
email.set("whyoleg@gmail.com")
}
}
maven {
name = "projectLocal"
url = uri(rootProject.layout.buildDirectory.dir("mavenProjectLocal"))
}
}

publications.withType<MavenPublication>().configureEach {
artifact(javadocJar)
pom {
name.set(project.name)
description.set(provider {
checkNotNull(project.description) { "Project description isn't set for project: ${project.path}" }
})
scm {
connection.set("https://github.com/whyoleg/cryptography-kotlin.git")
developerConnection.set("https://github.com/whyoleg/cryptography-kotlin.git")
url.set("https://github.com/whyoleg/cryptography-kotlin")

licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("whyoleg")
name.set("Oleg Yukhnevich")
email.set("whyoleg@gmail.com")
}
}
scm {
connection.set("https://github.com/whyoleg/cryptography-kotlin.git")
developerConnection.set("https://github.com/whyoleg/cryptography-kotlin.git")
url.set("https://github.com/whyoleg/cryptography-kotlin")
}
}
}
}

// javadocJar setup
// we have a single javadoc artifact which is used for all publications,
// and so we need to manually create task dependencies to make Gradle happy
val javadocJar by tasks.registering(Jar::class) { archiveClassifier.set("javadoc") }
tasks.withType<Sign>().configureEach { dependsOn(javadocJar) }
tasks.withType<AbstractPublishToMaven>().configureEach { dependsOn(tasks.withType<Sign>()) }
publishing.publications.withType<MavenPublication>().configureEach { artifact(javadocJar) }
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ gradle-customUserData = "1.12.1"
gradle-foojay = "0.8.0"
buildconfig = "5.3.5"
apache-commons-compress = "1.25.0"
maven-publish = "0.28.0"

# other
bouncycastle = "1.77"
Expand All @@ -39,6 +40,8 @@ build-gradle-foojay = { module = "org.gradle.toolchains:foojay-resolver", versio

build-apache-commons-compress = { module = "org.apache.commons:commons-compress", version.ref = "apache-commons-compress" }

maven-publish-gradle-plugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "maven-publish" }

kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" }
kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kotlinx-serialization" }
Expand Down

0 comments on commit a60ab23

Please sign in to comment.