Skip to content

Commit 4236a7e

Browse files
authored
Maven central publication (#1319)
Publication to Maven Central instead of Bintray
1 parent fc1e1a9 commit 4236a7e

File tree

5 files changed

+139
-29
lines changed

5 files changed

+139
-29
lines changed

RELEASING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ To release new `<version>` of `kotlinx.serialization`:
3434
* On 'Changes' tab, select `dev` branch and corresponding commit.
3535
* On 'Parameters' tab, find 'Deploy version' and fill in with `<version>`.
3636

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

4141
5. Update documentation website:<br>
4242
`./update_docs.sh <version> push`

buildSrc/build.gradle.kts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import org.jetbrains.kotlin.gradle.plugin.*
2+
import java.util.*
3+
4+
plugins {
5+
`kotlin-dsl`
6+
}
7+
8+
repositories {
9+
jcenter()
10+
}
11+
12+
kotlinDslPluginOptions {
13+
experimentalWarning.set(false)
14+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
@file:Suppress("UnstableApiUsage")
6+
7+
import org.gradle.api.*
8+
import org.gradle.api.artifacts.dsl.*
9+
import org.gradle.api.provider.*
10+
import org.gradle.api.publish.maven.*
11+
import org.gradle.plugins.signing.*
12+
import java.net.*
13+
14+
// Pom configuration
15+
16+
infix fun <T> Property<T>.by(value: T) {
17+
set(value)
18+
}
19+
20+
fun MavenPom.configureMavenCentralMetadata(project: Project) {
21+
name by project.name
22+
description by "Kotlin multiplatform serialization runtime library"
23+
url by "https://github.com/Kotlin/kotlinx.serialization"
24+
25+
licenses {
26+
license {
27+
name by "The Apache Software License, Version 2.0"
28+
url by "https://www.apache.org/licenses/LICENSE-2.0.txt"
29+
distribution by "repo"
30+
}
31+
}
32+
33+
developers {
34+
developer {
35+
id by "JetBrains"
36+
name by "JetBrains Team"
37+
organization by "JetBrains"
38+
organizationUrl by "https://www.jetbrains.com"
39+
}
40+
}
41+
42+
scm {
43+
url by "https://github.com/Kotlin/kotlinx.serialization"
44+
}
45+
}
46+
47+
fun configureBintrayPublication(rh: RepositoryHandler, project: Project) {
48+
rh.maven {
49+
val user = "kotlin"
50+
val repo = "kotlinx"
51+
val name = "kotlinx.serialization"
52+
url = URI("https://api.bintray.com/maven/$user/$repo/$name/;publish=0;override=0")
53+
54+
credentials {
55+
username = project.findProperty("bintrayUser") as? String ?: System.getenv("BINTRAY_USER")
56+
password = project.findProperty("bintrayApiKey") as? String ?: System.getenv("BINTRAY_API_KEY")
57+
}
58+
}
59+
}
60+
61+
fun mavenRepositoryUri(): URI {
62+
// TODO -SNAPSHOT detection can be made here as well
63+
val repositoryId: String? = System.getenv("libs.repository.id")
64+
return if (repositoryId == null) {
65+
// Using implicitly created staging, for MPP it's likely to be a mistake because
66+
// publication on TeamCity will create 3 independent staging repositories
67+
System.err.println("Warning: using an implicitly created staging for serialization")
68+
URI("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
69+
} else {
70+
URI("https://oss.sonatype.org/service/local/staging/deployByRepositoryId/$repositoryId")
71+
}
72+
}
73+
74+
fun configureMavenPublication(rh: RepositoryHandler, project: Project) {
75+
rh.maven {
76+
url = mavenRepositoryUri()
77+
credentials {
78+
username = project.getSensitiveProperty("libs.sonatype.user")
79+
password = project.getSensitiveProperty("libs.sonatype.password")
80+
}
81+
}
82+
}
83+
84+
fun signPublicationIfKeyPresent(project: Project, publication: MavenPublication) {
85+
val keyId = project.getSensitiveProperty("libs.sign.key.id")
86+
val signingKey = project.getSensitiveProperty("libs.sign.key.private")
87+
val signingKeyPassphrase = project.getSensitiveProperty("libs.sign.passphrase")
88+
if (!signingKey.isNullOrBlank()) {
89+
project.extensions.configure<SigningExtension>("signing") {
90+
useInMemoryPgpKeys(keyId, signingKey, signingKeyPassphrase)
91+
sign(publication)
92+
}
93+
}
94+
}
95+
96+
private fun Project.getSensitiveProperty(name: String): String? {
97+
return project.findProperty(name) as? String ?: System.getenv(name)
98+
}

gradle/bintray.gradle

Lines changed: 0 additions & 19 deletions
This file was deleted.

gradle/publishing.gradle

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import org.gradle.util.VersionNumber
22

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

77
// Configures publishing of Maven artifacts to Bintray
88

99
apply plugin: 'maven'
1010
apply plugin: 'maven-publish'
11+
apply plugin: 'signing'
1112

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

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

1920
task stubSources(type: Jar) {
20-
classifier = 'sources'
21+
archiveClassifier = 'sources'
2122
}
2223

2324
task stubJavadoc(type: Jar) {
24-
classifier = 'javadoc'
25+
archiveClassifier = 'javadoc'
2526
}
2627

2728
task emptyJar(type: Jar) {
2829
}
2930

31+
def bintrayUploadFlag = System.getenv("libs.bintray.upload") != null
32+
3033
afterEvaluate {
3134
task mainSourcesJar(type: Jar) {
3235
classifier = 'sources'
@@ -49,7 +52,11 @@ afterEvaluate {
4952
publication.from components.java
5053
publication.artifact mainSourcesJar
5154
artifact stubJavadoc
52-
publication.pom.withXml(configureMavenCentralMetadata)
55+
56+
PublishingKt.configureMavenCentralMetadata(publication.pom, project)
57+
if (!bintrayUploadFlag) {
58+
PublishingKt.signPublicationIfKeyPresent(project, publication)
59+
}
5360
}
5461
}
5562

@@ -92,7 +99,10 @@ afterEvaluate {
9299
}
93100
logger.info("Artifact id = ${it.artifactId}")
94101

95-
pom.withXml(configureMavenCentralMetadata)
102+
PublishingKt.configureMavenCentralMetadata(pom, project)
103+
if (!bintrayUploadFlag) {
104+
PublishingKt.signPublicationIfKeyPresent(project, it)
105+
}
96106

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

109-
110-
apply from: project.rootProject.file("gradle/bintray.gradle")
119+
publishing {
120+
repositories {
121+
if (bintrayUploadFlag) {
122+
PublishingKt.configureBintrayPublication(delegate, project)
123+
} else {
124+
PublishingKt.configureMavenPublication(delegate, project)
125+
}
126+
}
127+
}
111128

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

0 commit comments

Comments
 (0)