Skip to content

Commit

Permalink
Migrate Publishing to vanniktech plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Aug 5, 2023
1 parent 892a770 commit f57882f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 75 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/deployment-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ jobs:
!contains(github.event.head_commit.message, '[publish skip]') && github.event_name != 'pull_request' && github.ref != 'refs/heads/master'
env:
KORD_TEST_TOKEN: ${{ secrets.KORD_TEST_TOKEN }}
NEXUS_USER: ${{ secrets.NEXUS_USER }}
NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
SIGNING_KEY: ${{ secrets.signingKey }}
SIGNING_PASSWORD: ${{ secrets.signingPassword }}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.NEXUS_USER }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.NEXUS_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.signingKey }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.signingPassword }}
steps:
- uses: actions/checkout@v3
with:
Expand Down
11 changes: 5 additions & 6 deletions buildSrc/src/main/kotlin/kord-module.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.KotlinJvm
import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

Expand All @@ -8,7 +10,7 @@ plugins {
`kotlinx-atomicfu`
org.jetbrains.kotlinx.`binary-compatibility-validator`
com.google.devtools.ksp
`maven-publish`
id("com.vanniktech.maven.publish.base")
}

repositories {
Expand Down Expand Up @@ -51,9 +53,6 @@ tasks {
}
}

publishing {
publications.register<MavenPublication>(Library.name) {
from(components["java"])
artifact(tasks.kotlinSourcesJar)
}
mavenPublishing {
configure(KotlinJvm(javadocJar = JavadocJar.Dokka("dokkaHtml")))
}
7 changes: 7 additions & 0 deletions buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.KotlinMultiplatform
import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest

Expand All @@ -8,6 +10,7 @@ plugins {
`kotlinx-atomicfu`
org.jetbrains.kotlinx.`binary-compatibility-validator`
com.google.devtools.ksp
id("com.vanniktech.maven.publish.base")
}

repositories {
Expand Down Expand Up @@ -92,3 +95,7 @@ tasks {
dependsOn("kspCommonMainKotlinMetadata")
}
}

mavenPublishing {
configure(KotlinMultiplatform(javadocJar = JavadocJar.Dokka("dokkaHtml")))
}
99 changes: 35 additions & 64 deletions buildSrc/src/main/kotlin/kord-publishing.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,79 +1,50 @@
import java.lang.System.getenv
import java.util.Base64

plugins {
`maven-publish`
signing
// For some reason, Gradle does not generate an accessor for this
id("com.vanniktech.maven.publish.base")
}

fun MavenPublication.registerDokkaJar() =
tasks.register<Jar>("${name}DokkaJar") {
archiveClassifier = "javadoc"
destinationDirectory = destinationDirectory.get().dir(name)
from(tasks.named("dokkaHtml"))
}

publishing {
publications {
withType<MavenPublication>().configureEach {
if (project.name != "bom") artifact(registerDokkaJar())

groupId = Library.group
artifactId = "kord-$artifactId"
version = libraryVersion
group = Library.group
version = libraryVersion

pom {
name = Library.name
description = Library.description
url = Library.projectUrl
mavenPublishing {
coordinates(Library.group, "kord-${project.name}", libraryVersion)
// This sets up OSSRH snapshots + maven central
publishToMavenCentral(automaticRelease = true)
signAllPublications()

organization {
name = "Kord"
url = "https://github.com/kordlib"
}
pom {
name = Library.name
description = Library.description
url = Library.projectUrl

developers {
developer {
name = "The Kord Team"
}
}

issueManagement {
system = "GitHub"
url = "https://github.com/kordlib/kord/issues"
}

licenses {
license {
name = "MIT"
url = "https://opensource.org/licenses/MIT"
}
}
organization {
name = "Kord"
url = "https://github.com/kordlib"
}

scm {
connection = "scm:git:ssh://github.com/kordlib/kord.git"
developerConnection = "scm:git:ssh://git@github.com:kordlib/kord.git"
url = Library.projectUrl
}
developers {
developer {
name = "The Kord Team"
}
}
}

repositories {
maven {
url = uri(if (isRelease) Repo.releasesUrl else Repo.snapshotsUrl)
issueManagement {
system = "GitHub"
url = "https://github.com/kordlib/kord/issues"
}

credentials {
username = getenv("NEXUS_USER")
password = getenv("NEXUS_PASSWORD")
licenses {
license {
name = "MIT"
url = "https://opensource.org/licenses/MIT"
distribution = "https://github.com/kordlib/kord/blob/LICENSE"
}
}
}
}

signing {
val secretKey = getenv("SIGNING_KEY")?.let { String(Base64.getDecoder().decode(it)) }
val password = getenv("SIGNING_PASSWORD")
useInMemoryPgpKeys(secretKey, password)
sign(publishing.publications)
scm {
connection = "scm:git:ssh://github.com/kordlib/kord.git"
developerConnection = "scm:git:ssh://git@github.com:kordlib/kord.git"
url = Library.projectUrl
}
}
}
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dokka = "1.8.20" # https://github.com/Kotlin/dokka
kotlinx-atomicfu = "0.21.0" # https://github.com/Kotlin/kotlinx-atomicfu
binary-compatibility-validator = "0.13.2" # https://github.com/Kotlin/binary-compatibility-validator
buildconfig = "4.1.2" # https://github.com/gmazzo/gradle-buildconfig-plugin
maven-publish-plugin = "0.25.3"


[libraries]
Expand Down Expand Up @@ -84,7 +85,7 @@ dokka-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref
atomicfu-plugin = { module = "org.jetbrains.kotlinx:atomicfu-gradle-plugin", version.ref = "kotlinx-atomicfu" }
binary-compatibility-validator-plugin = { module = "org.jetbrains.kotlinx:binary-compatibility-validator", version.ref = "binary-compatibility-validator" }
ksp-plugin = { module = "com.google.devtools.ksp:symbol-processing-gradle-plugin", version.ref = "ksp" }

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

[bundles]

Expand All @@ -101,6 +102,7 @@ pluginsForBuildSrc = [
"atomicfu-plugin",
"binary-compatibility-validator-plugin",
"ksp-plugin",
"maven-publish-plugin"
]


Expand Down

0 comments on commit f57882f

Please sign in to comment.