Skip to content

Commit

Permalink
Use Nexus publish plugin for publishing to Sonatype
Browse files Browse the repository at this point in the history
  • Loading branch information
kamildoleglo committed Mar 15, 2021
1 parent 05ae0ef commit f10455d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 23 deletions.
15 changes: 15 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import org.jetbrains.ValidatePublications
import org.jetbrains.configureDokkaVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.publicationChannels

plugins {
kotlin("jvm") apply false
id("java")
id("org.jetbrains.dokka") version "1.4.20"
id("io.github.gradle-nexus.publish-plugin")
}

val dokka_version: String by project
Expand Down Expand Up @@ -79,3 +81,16 @@ tasks.whenTaskAdded {

println("Publication version: $dokka_version")
tasks.register<ValidatePublications>("validatePublications")

nexusPublishing {
repositories {
sonatype {
username.set(System.getenv("SONATYPE_USER"))
password.set(System.getenv("SONATYPE_PASSWORD"))
}
}
}

tasks.maybeCreate("dokkaPublish").run {
finalizedBy(tasks.named("closeAndReleaseSonatypeStagingRepository"))
}
2 changes: 2 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ plugins {
repositories {
mavenCentral()
jcenter()
maven("https://plugins.gradle.org/m2/")
}

dependencies {
implementation("com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4")
implementation("com.github.jengelman.gradle.plugins:shadow:2.0.4")
implementation("io.github.gradle-nexus:publish-plugin:1.0.0")
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/org/jetbrains/DokkaVersion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ val Project.dokkaVersion: String
get() = configureDokkaVersion()

val Project.dokkaVersionType: DokkaVersionType
get() = DokkaVersionType.values().find { it.suffix.matches(dokkaVersion.substringAfter("-")) }
get() = DokkaVersionType.values().find { it.suffix.matches(dokkaVersion.substringAfter("-", "")) }
?: throw IllegalStateException("Unrecognized version type: $dokkaVersion")
31 changes: 10 additions & 21 deletions buildSrc/src/main/kotlin/org/jetbrains/publication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.gradle.api.publish.maven.tasks.PublishToMavenRepository
import org.gradle.kotlin.dsl.*
import org.gradle.plugins.signing.SigningExtension
import org.jetbrains.DokkaPublicationChannel.*
import io.github.gradlenexus.publishplugin.NexusPublishExtension
import java.net.URI

class DokkaPublicationBuilder {
Expand Down Expand Up @@ -79,9 +80,14 @@ fun Project.configureSpacePublicationIfNecessary(vararg publications: String) {

fun Project.createDokkaPublishTaskIfNecessary() {
tasks.maybeCreate("dokkaPublish").run {
if (publicationChannels.any { it.isSpaceRepository } || publicationChannels.any { it.isMavenRepository }) {
if (publicationChannels.any { it.isSpaceRepository }) {
dependsOn(tasks.named("publish"))
}

if (publicationChannels.any { it.isMavenRepository }) {
dependsOn(tasks.named("publishToSonatype"))
}

if (publicationChannels.any { it.isBintrayRepository }) {
dependsOn(tasks.named("bintrayUpload"))
}
Expand Down Expand Up @@ -130,29 +136,10 @@ private fun Project.configureBintrayPublication(vararg publications: String) {

fun Project.configureSonatypePublicationIfNecessary(vararg publications: String) {
if (publicationChannels.any { it.isMavenRepository }) {
configureSonatypePublication(*publications)
signPublicationsIfKeyPresent(*publications)
}
}

private fun Project.configureSonatypePublication(vararg publications: String) {
configure<PublishingExtension> {
repositories {
maven {
if (MavenCentral in publicationChannels) {
url = URI("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
} else if (MavenCentralSnapshot in publicationChannels) {
url = URI("https://oss.sonatype.org/content/repositories/snapshots/")
}
credentials {
username = System.getenv("SONATYPE_USER")
password = System.getenv("SONATYPE_PASSWORD")
}
}
}
}
}

private fun Project.assertPublicationVersion() {
if (System.getenv("SKIP_VERSION_CHECK")?.contains("true", ignoreCase = true) == true)
return
Expand All @@ -161,7 +148,9 @@ private fun Project.assertPublicationVersion() {
publicationChannel.acceptedDokkaVersionTypes.any { acceptedVersionType ->
acceptedVersionType == dokkaVersionType
}
}) { throw AssertionError("Wrong version $dokkaVersion for configured publication channels $publicationChannels") }
}) {
throw AssertionError("Wrong version $dokkaVersion for configured publication channels $publicationChannels")
}
}

fun MavenPublication.configurePom(projectName: String) {
Expand Down
2 changes: 1 addition & 1 deletion runners/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ subprojects {
plugin("maven-publish")
plugin("com.jfrog.bintray")
}
}
}

0 comments on commit f10455d

Please sign in to comment.