Skip to content

Commit

Permalink
Maven central publication (#1319)
Browse files Browse the repository at this point in the history
Publication to Maven Central instead of Bintray
  • Loading branch information
shanshin authored Feb 3, 2021
1 parent fc1e1a9 commit 4236a7e
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 29 deletions.
6 changes: 3 additions & 3 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ To release new `<version>` of `kotlinx.serialization`:
* On 'Changes' tab, select `dev` branch and corresponding commit.
* On 'Parameters' tab, find 'Deploy version' and fill in with `<version>`.

4. In [Bintray](https://bintray.com/kotlin/kotlinx/kotlinx.serialization.runtime) admin interface:
* Publish artifacts of the new version.
* Wait until newly published version becomes the most recent.
4. In [Sonatype](oss.sonatype.org/#stagingRepositories) admin interface:
* Close the repository and wait for it to verify.
* Release it.

5. Update documentation website:<br>
`./update_docs.sh <version> push`
Expand Down
14 changes: 14 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import org.jetbrains.kotlin.gradle.plugin.*
import java.util.*

plugins {
`kotlin-dsl`
}

repositories {
jcenter()
}

kotlinDslPluginOptions {
experimentalWarning.set(false)
}
98 changes: 98 additions & 0 deletions buildSrc/src/main/kotlin/Publishing.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

@file:Suppress("UnstableApiUsage")

import org.gradle.api.*
import org.gradle.api.artifacts.dsl.*
import org.gradle.api.provider.*
import org.gradle.api.publish.maven.*
import org.gradle.plugins.signing.*
import java.net.*

// Pom configuration

infix fun <T> Property<T>.by(value: T) {
set(value)
}

fun MavenPom.configureMavenCentralMetadata(project: Project) {
name by project.name
description by "Kotlin multiplatform serialization runtime library"
url by "https://github.com/Kotlin/kotlinx.serialization"

licenses {
license {
name by "The Apache Software License, Version 2.0"
url by "https://www.apache.org/licenses/LICENSE-2.0.txt"
distribution by "repo"
}
}

developers {
developer {
id by "JetBrains"
name by "JetBrains Team"
organization by "JetBrains"
organizationUrl by "https://www.jetbrains.com"
}
}

scm {
url by "https://github.com/Kotlin/kotlinx.serialization"
}
}

fun configureBintrayPublication(rh: RepositoryHandler, project: Project) {
rh.maven {
val user = "kotlin"
val repo = "kotlinx"
val name = "kotlinx.serialization"
url = URI("https://api.bintray.com/maven/$user/$repo/$name/;publish=0;override=0")

credentials {
username = project.findProperty("bintrayUser") as? String ?: System.getenv("BINTRAY_USER")
password = project.findProperty("bintrayApiKey") as? String ?: System.getenv("BINTRAY_API_KEY")
}
}
}

fun mavenRepositoryUri(): URI {
// TODO -SNAPSHOT detection can be made here as well
val repositoryId: String? = System.getenv("libs.repository.id")
return if (repositoryId == null) {
// Using implicitly created staging, for MPP it's likely to be a mistake because
// publication on TeamCity will create 3 independent staging repositories
System.err.println("Warning: using an implicitly created staging for serialization")
URI("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
} else {
URI("https://oss.sonatype.org/service/local/staging/deployByRepositoryId/$repositoryId")
}
}

fun configureMavenPublication(rh: RepositoryHandler, project: Project) {
rh.maven {
url = mavenRepositoryUri()
credentials {
username = project.getSensitiveProperty("libs.sonatype.user")
password = project.getSensitiveProperty("libs.sonatype.password")
}
}
}

fun signPublicationIfKeyPresent(project: Project, publication: MavenPublication) {
val keyId = project.getSensitiveProperty("libs.sign.key.id")
val signingKey = project.getSensitiveProperty("libs.sign.key.private")
val signingKeyPassphrase = project.getSensitiveProperty("libs.sign.passphrase")
if (!signingKey.isNullOrBlank()) {
project.extensions.configure<SigningExtension>("signing") {
useInMemoryPgpKeys(keyId, signingKey, signingKeyPassphrase)
sign(publication)
}
}
}

private fun Project.getSensitiveProperty(name: String): String? {
return project.findProperty(name) as? String ?: System.getenv(name)
}
19 changes: 0 additions & 19 deletions gradle/bintray.gradle

This file was deleted.

31 changes: 24 additions & 7 deletions gradle/publishing.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import org.gradle.util.VersionNumber

/*
* Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

// Configures publishing of Maven artifacts to Bintray

apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'signing'

apply from: project.rootProject.file('gradle/maven-metadata.gradle')

Expand All @@ -17,16 +18,18 @@ def isMultiplatform = project.name in ["kotlinx-serialization-core", "kotlinx-se
def isKotlin137x = VersionNumber.parse(kotlin_version) <= VersionNumber.parse("1.3.79")

task stubSources(type: Jar) {
classifier = 'sources'
archiveClassifier = 'sources'
}

task stubJavadoc(type: Jar) {
classifier = 'javadoc'
archiveClassifier = 'javadoc'
}

task emptyJar(type: Jar) {
}

def bintrayUploadFlag = System.getenv("libs.bintray.upload") != null

afterEvaluate {
task mainSourcesJar(type: Jar) {
classifier = 'sources'
Expand All @@ -49,7 +52,11 @@ afterEvaluate {
publication.from components.java
publication.artifact mainSourcesJar
artifact stubJavadoc
publication.pom.withXml(configureMavenCentralMetadata)

PublishingKt.configureMavenCentralMetadata(publication.pom, project)
if (!bintrayUploadFlag) {
PublishingKt.signPublicationIfKeyPresent(project, publication)
}
}
}

Expand Down Expand Up @@ -92,7 +99,10 @@ afterEvaluate {
}
logger.info("Artifact id = ${it.artifactId}")

pom.withXml(configureMavenCentralMetadata)
PublishingKt.configureMavenCentralMetadata(pom, project)
if (!bintrayUploadFlag) {
PublishingKt.signPublicationIfKeyPresent(project, it)
}

// The 'root' module publishes the JVM module's Javadoc JAR as per publishPlatformArtifactsInRootModule, and
// every other module should publish an empty Javadoc JAR. TODO: provide proper documentation artifacts?
Expand All @@ -106,8 +116,15 @@ afterEvaluate {
}
}


apply from: project.rootProject.file("gradle/bintray.gradle")
publishing {
repositories {
if (bintrayUploadFlag) {
PublishingKt.configureBintrayPublication(delegate, project)
} else {
PublishingKt.configureMavenPublication(delegate, project)
}
}
}

// Compatibility with old TeamCity configurations that perform :kotlinx-coroutines-core:bintrayUpload
task bintrayUpload(dependsOn: publish)
Expand Down

0 comments on commit 4236a7e

Please sign in to comment.