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 3e466c9 commit 3c05c9b
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 100 deletions.
20 changes: 6 additions & 14 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,10 @@ jobs:
with:
cache-disabled: true

- name: Publish to Maven Local (prepare packages)
run: ./gradlew publishToMavenLocal -Pversion=${{ github.ref_name }} --no-configuration-cache
- name: Publish release to Maven Central
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}}

- name: Publish release to Maven Central (version ${{ github.ref_name }})
run: ./gradlew publishAllPublicationsToSonatypeRepository -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}}
12 changes: 7 additions & 5 deletions .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ jobs:
branch_name="${ref_name////-}"
echo "::set-output name=version-suffix::$branch_name"
- name: Publish to Maven Local (prepare packages)
run: ./gradlew publishToMavenLocal -PversionSuffix=${{ steps.set-version.outputs.version-suffix }} -PgithubUsername=${{ github.actor }} -PgithubPassword=${{ github.token }} --no-configuration-cache

- name: Publish snapshot to Github Packages (version x.y.z-${{ steps.set-version.outputs.version-suffix }}-SNAPSHOT)
run: ./gradlew publishAllPublicationsToGithubRepository -PversionSuffix=${{ steps.set-version.outputs.version-suffix }} -PgithubUsername=${{ github.actor }} -PgithubPassword=${{ github.token }} --no-configuration-cache
- name: Publish snapshot to Maven Central
run: ./gradlew publishToMavenCentral -Pversion=0.16.0-${{ steps.set-version.outputs.version-suffix }}-SNAPSHOT --no-configuration-cache
env:
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 @@ -22,4 +22,5 @@ dependencies {
implementation(libs.kotlin.gradle.plugin)
implementation(libs.kotlinx.bcv.gradle.plugin)
implementation(libs.kotlinx.atomicfu.gradle.plugin)
implementation(libs.maven.publish.gradle.plugin)
}
118 changes: 38 additions & 80 deletions build-logic/src/main/kotlin/rsocketbuild.publication.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,96 +14,54 @@
* limitations under the License.
*/

plugins {
`maven-publish`
signing
}

val githubUsername: String? by project
val githubPassword: String? by project

val sonatypeUsername: String? by project
val sonatypePassword: String? by project

val signingKey: String? by project
val signingPassword: String? by project
import com.vanniktech.maven.publish.*

// TODO: refactor publication a bit, so that version in gradle.properties will not contain SNAPSHOT
val versionSuffix = providers.gradleProperty("rsocketbuild.versionSuffix").orNull
if (versionSuffix != null) {
val versionString = project.version.toString()
require(versionString.endsWith("-SNAPSHOT"))
project.version = versionString.replace("-", "-${versionSuffix}-")
println("Current version: ${project.version}")
plugins {
id("com.vanniktech.maven.publish.base")
}

// empty javadoc for maven central
val javadocJar by tasks.registering(Jar::class) { archiveClassifier.set("javadoc") }

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

publishing {
publications.withType<MavenPublication> {
artifact(javadocJar)
pom {
name.set(project.name)
description.set(provider {
checkNotNull(project.description) { "Project description isn't set for project: ${project.path}" }
})
url.set("http://rsocket.io")
pom {
name.set(project.name)
description.set(provider {
checkNotNull(project.description) { "Project description isn't set for project: ${project.path}" }
})
url.set("https://rsocket.io")

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("[email protected]")
}
developer {
id.set("OlegDokuka")
name.set("Oleh Dokuka")
email.set("[email protected]")
}
}
scm {
connection.set("https://github.com/rsocket/rsocket-kotlin.git")
developerConnection.set("https://github.com/rsocket/rsocket-kotlin.git")
url.set("https://github.com/rsocket/rsocket-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")
}
}
}

repositories {
// TODO: drop github and use sonatype (?)
maven {
name = "github"
url = uri("https://maven.pkg.github.com/rsocket/rsocket-kotlin")
credentials {
username = githubUsername
password = githubPassword
developers {
developer {
id.set("whyoleg")
name.set("Oleg Yukhnevich")
email.set("[email protected]")
}
}
maven {
name = "sonatype"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2")
credentials {
username = sonatypeUsername
password = sonatypePassword
developer {
id.set("OlegDokuka")
name.set("Oleh Dokuka")
email.set("[email protected]")
}
}
scm {
connection.set("https://github.com/rsocket/rsocket-kotlin.git")
developerConnection.set("https://github.com/rsocket/rsocket-kotlin.git")
url.set("https://github.com/rsocket/rsocket-kotlin")
}
}
}

signing {
isRequired = sonatypeUsername != null && sonatypePassword != null
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications)
}
// 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) }
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
#
group=io.rsocket.kotlin
version=0.16.0-SNAPSHOT
version=0.16.0
#Kotlin
kotlin.mpp.import.enableKgpDependencyResolution=true
kotlin.native.ignoreDisabledTargets=true
Expand Down
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ rsocket-java = "1.1.3"

jmh = "1.36"

maven-publish = "0.28.0"

[libraries]
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" }
Expand Down Expand Up @@ -45,6 +47,7 @@ rsocket-java-transport-local = { module = 'io.rsocket:rsocket-transport-local',
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlinx-atomicfu-gradle-plugin = { module = "org.jetbrains.kotlinx:atomicfu-gradle-plugin", version.ref = "kotlinx-atomicfu" }
kotlinx-bcv-gradle-plugin = { module = "org.jetbrains.kotlinx:binary-compatibility-validator", version.ref = "kotlinx-bcv" }
maven-publish-gradle-plugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "maven-publish" }

[plugins]
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
Expand Down

0 comments on commit 3c05c9b

Please sign in to comment.