Skip to content

Commit

Permalink
use vanniktech maven publish
Browse files Browse the repository at this point in the history
  • Loading branch information
ronjunevaldoz committed Sep 25, 2024
1 parent 10488e3 commit 510acf0
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 70 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,30 @@ implementation("io.github.ronjunevaldoz:kpaymongo-jvm:1.0.0-SNAPSHOT"){
isChanging = true // this will allow to get all latest changes
}
```

## How do I deploy it to Maven Central?

The most part of the job is already automated for you. However, deployment to Maven Central requires some manual work from your side.

1. - [ ] Create an account at [Sonatype issue tracker](https://issues.sonatype.org/secure/Signup!default.jspa)
2. - [ ] [Create an issue](https://issues.sonatype.org/secure/CreateIssue.jspa?issuetype=21&pid=10134) to create new project for you
3. - [ ] You will have to prove that you own your desired namespace
4. - [ ] Create a GPG key with `gpg --gen-key`, use the same email address you used to sign up to the Sonatype Jira
5. - [ ] Find your key id in the output of the previous command looking like `D89FAAEB4CECAFD199A2F5E612C6F735F7A9A519`
6. - [ ] Upload your key to a keyserver, for example
```bash
gpg --send-keys --keyserver keyserver.ubuntu.com "<your key id>"
```
1. - [ ] Now you should create secrets available to your GitHub Actions
1. via `gh` command

```bash
gh secret set SIGNING_KEY -a actions --body "$(gpg --export-secret-key --armor "<KEY_ID>")"
gh secret set SIGNING_KEY_ID -a actions --body "<KEY_ID>"
gh secret set SIGNING_KEY_PASSWORD -a actions --body "<SECRET_PASSWORD>"
gh secret set MAVEN_CENTRAL_PASSWORD -a actions --body "<GENERATED_PASSWORD>"
gh secret set MAVEN_CENTRAL_USERNAME -a actions --body "<GENERATED_USERNAME>"
```

1- [ ] Deploy command
`./gradlew publishAndReleaseToMavenCentral --no-configuration-cache`
2 changes: 1 addition & 1 deletion convention-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ plugins {
}

dependencies {
implementation(libs.nexus.publish)
implementation(libs.gradleMavenPublishPlugin)
implementation(libs.dokka.gradle)
}
100 changes: 45 additions & 55 deletions convention-plugins/src/main/kotlin/module.publication.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,55 +1,45 @@
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.`maven-publish`

plugins {
`maven-publish`
signing
}

publishing {
// Configure all publications
publications.withType<MavenPublication> {
// Stub javadoc.jar artifact
artifact(tasks.register("${name}JavadocJar", Jar::class) {
archiveClassifier.set("javadoc")
archiveAppendix.set(this@withType.name)
})

// Provide artifacts information required by Maven Central
pom {
name.set("KotlinPaymongo")
description.set("Paymongo Kotlin Client")
licenses {
license {
name.set("MIT")
url.set("https://opensource.org/licenses/MIT")
}
}
url.set("https://ronjunevaldoz.github.io/KotlinPaymongo")
issueManagement {
system.set("Github")
url.set("https://github.com/ronjunevaldoz/KotlinPaymongo/issues")
}
scm {
connection.set("https://github.com/ronjunevaldoz/KotlinPaymongo.git")
url.set("https://github.com/ronjunevaldoz/KotlinPaymongo")
}
developers {
developer {
name.set("Ron June Valdoz")
email.set("ronjune.lopez@gmail.com")
organization.set("Ron June Valdoz") // TODO update real org
organizationUrl.set("https://github.com/ronjunevaldoz") // TODO update real org url
}
}
}
}
}

signing {
if (project.hasProperty("signing.gnupg.keyName")) {
useGpgCmd()
sign(publishing.publications)
}
}
//import gradle.kotlin.dsl.accessors._8edd1b0c1852f0ac869e9c414c462ba9.mavenPublishing
//import org.gradle.api.publish.maven.MavenPublication
//import org.gradle.api.tasks.bundling.Jar
//import org.gradle.kotlin.dsl.`maven-publish`
//
//plugins {
// com.vanniktech.maven.publish
//}
//
//mavenPublishing {
// pom {
// name.set("KotlinPaymongo")
// description.set("Paymongo Kotlin Client")
// licenses {
// license {
// name.set("MIT")
// url.set("https://opensource.org/licenses/MIT")
// }
// }
// url.set("https://ronjunevaldoz.github.io/KotlinPaymongo")
// issueManagement {
// system.set("Github")
// url.set("https://github.com/ronjunevaldoz/KotlinPaymongo/issues")
// }
// scm {
// connection.set("https://github.com/ronjunevaldoz/KotlinPaymongo.git")
// url.set("https://github.com/ronjunevaldoz/KotlinPaymongo")
// }
// developers {
// developer {
// name.set("Ron June Valdoz")
// email.set("ronjune.lopez@gmail.com")
// organization.set("Ron June Valdoz") // TODO update real org
// organizationUrl.set("https://github.com/ronjunevaldoz") // TODO update real org url
// }
// }
// }
//}
//
//signing {
// if (project.hasProperty("signing.gnupg.keyName")) {
// useGpgCmd()
// sign(publishing.publications)
// }
//}
50 changes: 41 additions & 9 deletions convention-plugins/src/main/kotlin/root.publication.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,19 +1,51 @@
import gradle.kotlin.dsl.accessors._8edd1b0c1852f0ac869e9c414c462ba9.mavenPublishing
import com.vanniktech.maven.publish.SonatypeHost

plugins {
id("io.github.gradle-nexus.publish-plugin")
id("com.vanniktech.maven.publish")
}

allprojects {
group = "io.github.ronjunevaldoz"
version = "1.0.0-SNAPSHOT"
}

nexusPublishing {
// Configure maven central repository
// https://github.com/gradle-nexus/publish-plugin#publishing-to-maven-central-via-sonatype-ossrh
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/"))
mavenPublishing {
coordinates(
groupId = "io.github.ronjunevaldoz",
artifactId = "paymongo-kotlin",
version = "1.0.0-SNAPSHOT"
)
// Configure publishing to Maven Central
publishToMavenCentral(SonatypeHost.S01)
// Enable GPG signing for all publications
signAllPublications()

pom {
name.set("KotlinPaymongo")
description.set("Paymongo Kotlin Client")
licenses {
license {
name.set("MIT")
url.set("https://opensource.org/licenses/MIT")
}
}
url.set("https://ronjunevaldoz.github.io/KotlinPaymongo")
issueManagement {
system.set("Github")
url.set("https://github.com/ronjunevaldoz/KotlinPaymongo/issues")
}
scm {
connection.set("https://github.com/ronjunevaldoz/KotlinPaymongo.git")
url.set("https://github.com/ronjunevaldoz/KotlinPaymongo")
}
developers {
developer {
name.set("Ron June Valdoz")
email.set("ronjune.lopez@gmail.com")
organization.set("Ron June Valdoz") // TODO update real org
organizationUrl.set("https://github.com/ronjunevaldoz") // TODO update real org url
}
}
}
}
}
8 changes: 7 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ kotlin.code.style=official
kotlin.mpp.enableCInteropCommonization=true
#Android
android.useAndroidX=true
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true

mavenCentralUsername = boIuCxFM
mavenCentralPassword = uApwrHqwzeQmovi8TkhdgjHLdBpDrf6YjtbrlB4J5pFq
signing.keyId = D74907B2B4A5F529B26267B4C0A75DEB90BBC9CD
signing.password = Garcialopez1!
signing.secretKeyRingFile = ~/secret_key.gpg
8 changes: 5 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ktor = "3.0.0-rc-1"
logback = "1.5.6"
# Stately concurrent collections for WASM and JS
statelyConcurrentCollectionsWasmJs = "2.0.7"
nexus-publish = "2.0.0"
vanniktechPublish = "0.29.0"
dokka = "1.9.20"
androidx-activityCompose = "1.9.2"

Expand Down Expand Up @@ -50,7 +50,8 @@ stately-concurrent-collections-wasm-js = { module = "co.touchlab:stately-concurr
# Canard logging library
#canard = { module = "org.kodein.log:canard", version.ref = "canard" }
# Publishing
nexus-publish = { module = "io.github.gradle-nexus.publish-plugin:io.github.gradle-nexus.publish-plugin.gradle.plugin", version.ref = "nexus-publish" }
#nexus-publish = { module = "com.vanniktech.maven.publish", version.ref = "nexus-publish" }
gradleMavenPublishPlugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "vanniktechPublish" }
dokka-gradle = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }

[bundles]
Expand Down Expand Up @@ -83,4 +84,5 @@ ktor = { id = "io.ktor.plugin", version.ref = "ktor" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
# Kotlin Serialization plugin
kotlinSerialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
vanniktech-maven-publish = { id = "com.vanniktech.maven.publish", version.ref = "vanniktechPublish" }
4 changes: 3 additions & 1 deletion library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
alias(libs.plugins.kotlinSerialization)
id("module.publication")
id("root.publication")
}

kotlin {
withSourcesJar(publish = false)

jvm()
@OptIn(ExperimentalWasmDsl::class)
wasmJs {
Expand Down

0 comments on commit 510acf0

Please sign in to comment.