Skip to content

Commit c990568

Browse files
authored
Maven central publication (#2451)
1 parent 5954e40 commit c990568

File tree

4 files changed

+107
-60
lines changed

4 files changed

+107
-60
lines changed

RELEASE.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ To release new `<version>` of `kotlinx-coroutines`:
5959
(make sure you have [Docker](https://www.docker.com/) installed first): <br>
6060
`site/deploy.sh <version> push`
6161

62-
4. In [Bintray](https://bintray.com/kotlin/kotlinx/kotlinx.coroutines) admin interface:
63-
* Publish artifacts of the new version.
64-
* Wait until newly published version becomes the most recent.
65-
* Sync to Maven Central.
62+
4. In [Nexus](https://oss.sonatype.org/#stagingRepositories) admin interface:
63+
* Close the repository and wait for it to verify.
64+
* Release the repository.
6665

6766
5. Announce new release in [Slack](https://kotlinlang.slack.com)
6867

buildSrc/src/main/kotlin/MavenCentral.kt

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

gradle/publish-bintray.gradle

+11-19
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import org.gradle.util.VersionNumber
88

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

1213
// ------------- tasks
1314

@@ -36,16 +37,11 @@ if (!isMultiplatform && !isBom) {
3637

3738
publishing {
3839
repositories {
39-
maven {
40-
def user = 'kotlin'
41-
def repo = 'kotlinx'
42-
def name = 'kotlinx.coroutines'
43-
url = "https://api.bintray.com/maven/$user/$repo/$name/;publish=0"
44-
45-
credentials {
46-
username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER')
47-
password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY')
48-
}
40+
def bintrayUpload = System.getenv("libs.bintray.upload") != null
41+
if (bintrayUpload) {
42+
PublishingKt.configureBintrayPublication(delegate, project)
43+
} else {
44+
PublishingKt.configureMavenPublication(delegate, project)
4945
}
5046
}
5147

@@ -64,8 +60,11 @@ publishing {
6460
}
6561

6662
publications.all {
67-
MavenCentralKt.configureMavenCentralMetadata(pom, project)
68-
63+
PublishingKt.configureMavenCentralMetadata(pom, project)
64+
def bintrayUpload = System.getenv("libs.bintray.upload") != null
65+
if (!bintrayUpload) {
66+
PublishingKt.signPublicationIfKeyPresent(project, it)
67+
}
6968
// add empty javadocs
7069
if (!isBom && it.name != "kotlinMultiplatform") {
7170
it.artifact(javadocJar)
@@ -94,12 +93,5 @@ tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication"}.
9493
dependsOn(tasks["generatePomFileForJvmPublication"])
9594
}
9695

97-
task publishDevelopSnapshot() {
98-
def branch = System.getenv('currentBranch')
99-
if (branch == "develop") {
100-
dependsOn(":publish")
101-
}
102-
}
103-
10496
// Compatibility with old TeamCity configurations that perform :kotlinx-coroutines-core:bintrayUpload
10597
task bintrayUpload(dependsOn: publish)

0 commit comments

Comments
 (0)