-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathPublishing.kt
93 lines (80 loc) · 3.16 KB
/
Publishing.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* 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.Project
import org.gradle.api.artifacts.dsl.*
import org.gradle.api.publish.maven.*
import org.gradle.plugins.signing.*
import java.net.*
// Pom configuration
fun MavenPom.configureMavenCentralMetadata(project: Project) {
name by project.name
description by "Coroutines support libraries for Kotlin"
url by "https://github.com/Kotlin/kotlinx.coroutines"
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.coroutines"
}
}
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 coroutines")
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 configureBintrayPublication(rh: RepositoryHandler, project: Project) {
rh.maven {
val user = "kotlin"
val repo = "kotlinx"
val name = "kotlinx.coroutines"
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 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)
}