Vsevolod Tolstopyatov | c990568 | 2020-12-31 06:01:07 -0800 | [diff] [blame] | 1 | /* |
Vsevolod Tolstopyatov | 41a2e30 | 2021-02-04 07:16:48 -0800 | [diff] [blame] | 2 | * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
Vsevolod Tolstopyatov | c990568 | 2020-12-31 06:01:07 -0800 | [diff] [blame] | 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 { |
Vsevolod Tolstopyatov | c990568 | 2020-12-31 06:01:07 -0800 | [diff] [blame] | 43 | val repositoryId: String? = System.getenv("libs.repository.id") |
| 44 | return if (repositoryId == null) { |
Vsevolod Tolstopyatov | c990568 | 2020-12-31 06:01:07 -0800 | [diff] [blame] | 45 | URI("https://oss.sonatype.org/service/local/staging/deploy/maven2/") |
| 46 | } else { |
| 47 | URI("https://oss.sonatype.org/service/local/staging/deployByRepositoryId/$repositoryId") |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | fun configureMavenPublication(rh: RepositoryHandler, project: Project) { |
| 52 | rh.maven { |
| 53 | url = mavenRepositoryUri() |
| 54 | credentials { |
| 55 | username = project.getSensitiveProperty("libs.sonatype.user") |
| 56 | password = project.getSensitiveProperty("libs.sonatype.password") |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
Vsevolod Tolstopyatov | c990568 | 2020-12-31 06:01:07 -0800 | [diff] [blame] | 61 | fun signPublicationIfKeyPresent(project: Project, publication: MavenPublication) { |
| 62 | val keyId = project.getSensitiveProperty("libs.sign.key.id") |
| 63 | val signingKey = project.getSensitiveProperty("libs.sign.key.private") |
| 64 | val signingKeyPassphrase = project.getSensitiveProperty("libs.sign.passphrase") |
| 65 | if (!signingKey.isNullOrBlank()) { |
| 66 | project.extensions.configure<SigningExtension>("signing") { |
| 67 | useInMemoryPgpKeys(keyId, signingKey, signingKeyPassphrase) |
| 68 | sign(publication) |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | private fun Project.getSensitiveProperty(name: String): String? { |
| 74 | return project.findProperty(name) as? String ?: System.getenv(name) |
| 75 | } |