|
| 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 | +} |
0 commit comments