• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.Project
8 import org.gradle.api.artifacts.dsl.*
9 import org.gradle.api.publish.maven.*
10 import org.gradle.kotlin.dsl.*
11 import org.gradle.plugins.signing.*
12 import java.net.*
13 
14 // Pom configuration
15 
configureMavenCentralMetadatanull16 fun MavenPom.configureMavenCentralMetadata(project: Project) {
17     name by project.name
18     description by "Coroutines support libraries for Kotlin"
19     url by "https://github.com/Kotlin/kotlinx.coroutines"
20 
21     licenses {
22         license {
23             name by "The Apache Software License, Version 2.0"
24             url by "https://www.apache.org/licenses/LICENSE-2.0.txt"
25             distribution by "repo"
26         }
27     }
28 
29     developers {
30         developer {
31             id by "JetBrains"
32             name by "JetBrains Team"
33             organization by "JetBrains"
34             organizationUrl by "https://www.jetbrains.com"
35         }
36     }
37 
38     scm {
39         url by "https://github.com/Kotlin/kotlinx.coroutines"
40     }
41 }
42 
mavenRepositoryUrinull43 fun mavenRepositoryUri(): URI {
44     val repositoryId: String? = System.getenv("libs.repository.id")
45     return if (repositoryId == null) {
46         URI("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
47     } else {
48         URI("https://oss.sonatype.org/service/local/staging/deployByRepositoryId/$repositoryId")
49     }
50 }
51 
configureMavenPublicationnull52 fun configureMavenPublication(rh: RepositoryHandler, project: Project) {
53     rh.maven {
54         url = mavenRepositoryUri()
55         credentials {
56             username = project.getSensitiveProperty("libs.sonatype.user")
57             password = project.getSensitiveProperty("libs.sonatype.password")
58         }
59     }
60 
61     // Something that's easy to "clean" for development, not mavenLocal
62     rh.maven("${project.rootProject.buildDir}/repo") {
63         name = "buildRepo"
64     }
65 }
66 
signPublicationIfKeyPresentnull67 fun signPublicationIfKeyPresent(project: Project, publication: MavenPublication) {
68     val keyId = project.getSensitiveProperty("libs.sign.key.id")
69     val signingKey = project.getSensitiveProperty("libs.sign.key.private")
70     val signingKeyPassphrase = project.getSensitiveProperty("libs.sign.passphrase")
71     if (!signingKey.isNullOrBlank()) {
72         project.extensions.configure<SigningExtension>("signing") {
73             useInMemoryPgpKeys(keyId, signingKey, signingKeyPassphrase)
74             sign(publication)
75         }
76     }
77 }
78 
getSensitivePropertynull79 private fun Project.getSensitiveProperty(name: String): String? {
80     return project.findProperty(name) as? String ?: System.getenv(name)
81 }
82