Skip to content

Commit

Permalink
Maven publishing (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
phoebe-lew authored Jan 25, 2024
1 parent 04b3ff3 commit 3fba185
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 5 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Publish package to the Maven Central Repository
on:
workflow_dispatch:
inputs:
version:
description: 'Version to publish. For example "0.0.1"'
required: true
default: '0.0.0'
release:
types: [ published ]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Set up Java
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: '11'
- uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: gradle-ubuntu-latest-${{ hashFiles('**/*.gradle.kts') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/versions.properties') }}

- name: Sonatype Publish Close And Release
run: |
if [ -n "${{ github.event.inputs.version }}" ]; then
./gradlew -Pversion=${{ github.event.inputs.version }} publishToSonatype closeAndReleaseSonatypeStagingRepository
else
./gradlew -Pversion=$(echo "${{ github.ref_name }}" | cut -c2-) publishToSonatype closeAndReleaseSonatypeStagingRepository
fi
env:
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEY }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGPASSWORD }}
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPEUSERNAME }}
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPEPASSWORD }}
103 changes: 98 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ plugins {
`maven-publish`
id("org.jetbrains.dokka") version "1.9.0"
id("org.jetbrains.kotlinx.kover") version "0.7.3"
signing
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
}

repositories {
Expand All @@ -22,8 +24,7 @@ dependencies {
}

allprojects {
version = "0.6.0"
group = "tbdex"
group = "xyz.block"
}

subprojects {
Expand All @@ -34,6 +35,7 @@ subprojects {
plugin("maven-publish")
plugin("org.jetbrains.dokka")
plugin("org.jetbrains.kotlinx.kover")
plugin("signing")
}

tasks.withType<Detekt>().configureEach {
Expand All @@ -59,14 +61,51 @@ subprojects {
targetCompatibility = JavaVersion.VERSION_11
}

val publicationName = "${rootProject.name}-${project.name}"
publishing {
publications {
create<MavenPublication>("tbdex") {
create<MavenPublication>(publicationName) {
groupId = project.group.toString()
artifactId = project.name.toString()
version = project.version.toString()
artifactId = name
description = "Kotlin SDK for tbdex functionality"
version = project.property("version").toString()
from(components["java"])
}

withType<MavenPublication> {
pom {
name = publicationName
packaging = "jar"
description.set("tbdex kotlin SDK")
url.set("https://github.com/TBD54566975/tbdex-kt")
inceptionYear.set("2023")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("https://github.com/TBD54566975/tbdex-kt/blob/main/LICENSE")
}
}
developers {
developer {
id.set("TBD54566975")
name.set("Block Inc.")
email.set("tbd-releases@tbd.email")
}
}
scm {
connection.set("scm:git:git@github.com:TBD54566975/tbdex-kt.git")
developerConnection.set("scm:git:ssh:git@github.com:TBD54566975/tbdex-kt.git")
url.set("https://github.com/TBD54566975/tbdex-kt")
}
}
}
}

signing {
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications[publicationName])
}
}

Expand Down Expand Up @@ -108,4 +147,58 @@ subprojects {
// this will not affect subprojects
tasks.dokkaHtmlMultiModule {
moduleName.set("tbdex SDK Documentation")
}

publishing {
publications {
create<MavenPublication>("tbdex") {
groupId = project.group.toString()
artifactId = name
description = "Kotlin SDK for tbdex functionality"
version = project.property("version").toString()
from(components["java"])

pom {
packaging = "jar"
name = project.name
description.set("tbdex kotlin SDK")
url.set("https://github.com/TBD54566975/tbdex-kt")
inceptionYear.set("2023")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("https://github.com/TBD54566975/tbdex-kt/blob/main/LICENSE")
}
}
developers {
developer {
id.set("TBD54566975")
name.set("Block Inc.")
email.set("tbd-releases@tbd.email")
}
}
scm {
connection.set("scm:git:git@github.com:TBD54566975/tbdex-kt.git")
developerConnection.set("scm:git:ssh:git@github.com:TBD54566975/tbdex-kt.git")
url.set("https://github.com/TBD54566975/tbdex-kt")
}
}
}
}
}

signing {
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications["tbdex"])
}

nexusPublishing {
repositories {
sonatype { //only for users registered in Sonatype after 24 Feb 2021
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
}

0 comments on commit 3fba185

Please sign in to comment.