6
6
7
7
import org.gradle.api.*
8
8
import org.gradle.api.artifacts.dsl.*
9
+ import org.gradle.api.artifacts.repositories.PasswordCredentials
9
10
import org.gradle.api.provider.*
10
11
import org.gradle.api.publish.maven.*
12
+ import org.gradle.api.publish.PublishingExtension
11
13
import org.gradle.plugins.signing.*
12
14
import java.net.*
13
15
14
16
// Pom configuration
15
17
16
- fun mavenRepositoryUri (): URI {
17
- val repositoryId: String? = System .getenv(" libs.repository.id" )
18
- return if (repositoryId == null ) {
19
- // Using implicitly created staging, for MPP it's likely to be a mistake because
20
- // publication on TeamCity will create 3 independent staging repositories
21
- URI (" https://oss.sonatype.org/service/local/staging/deploy/maven2/" )
22
- } else {
23
- URI (" https://oss.sonatype.org/service/local/staging/deployByRepositoryId/$repositoryId " )
24
- }
25
- }
26
-
27
18
fun signPublicationIfKeyPresent (project : Project , publication : MavenPublication ) {
28
19
val keyId = project.getSensitiveProperty(" libs.sign.key.id" )
29
20
val signingKey = project.getSensitiveProperty(" libs.sign.key.private" )
@@ -36,6 +27,23 @@ fun signPublicationIfKeyPresent(project: Project, publication: MavenPublication)
36
27
}
37
28
}
38
29
30
+ fun PublishingExtension.addPublishingRepositoryIfPresent () {
31
+ val repoUrl = System .getenv(" libs.repo.url" )
32
+ if (! repoUrl.isNullOrBlank()) {
33
+ repositories {
34
+ maven {
35
+ // if you change the name, you should change the name of the credential properties on CI as well
36
+ name = " MavenRepositoryForPublishing"
37
+ url = URI (repoUrl)
38
+
39
+ // we use such type of credential because of the configuration cache problems with other types:
40
+ // https://github.com/gradle/gradle/issues/24040
41
+ credentials(PasswordCredentials ::class .java)
42
+ }
43
+ }
44
+ }
45
+ }
46
+
39
47
internal fun Project.getSensitiveProperty (name : String ): String? {
40
48
return project.findProperty(name) as ? String ? : System .getenv(name)
41
49
}
0 commit comments