Skip to content

Commit 2b7b810

Browse files
authored
Support a new publication scheme (#551)
1 parent 3eaebe6 commit 2b7b810

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

buildSrc/src/main/kotlin/Publishing.kt

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,15 @@
66

77
import org.gradle.api.*
88
import org.gradle.api.artifacts.dsl.*
9+
import org.gradle.api.artifacts.repositories.PasswordCredentials
910
import org.gradle.api.provider.*
1011
import org.gradle.api.publish.maven.*
12+
import org.gradle.api.publish.PublishingExtension
1113
import org.gradle.plugins.signing.*
1214
import java.net.*
1315

1416
// Pom configuration
1517

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-
2718
fun signPublicationIfKeyPresent(project: Project, publication: MavenPublication) {
2819
val keyId = project.getSensitiveProperty("libs.sign.key.id")
2920
val signingKey = project.getSensitiveProperty("libs.sign.key.private")
@@ -36,6 +27,23 @@ fun signPublicationIfKeyPresent(project: Project, publication: MavenPublication)
3627
}
3728
}
3829

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+
3947
internal fun Project.getSensitiveProperty(name: String): String? {
4048
return project.findProperty(name) as? String ?: System.getenv(name)
4149
}

buildSrc/src/main/kotlin/base-publish-conventions.gradle.kts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,8 @@ plugins {
44
}
55

66
publishing {
7-
repositories {
8-
maven {
9-
// if you change the name, you should change the name of the credential properties on CI as well
10-
name = "MavenRepositoryForPublishing"
7+
addPublishingRepositoryIfPresent()
118

12-
url = mavenRepositoryUri()
13-
14-
// we use such type of credential because of the configuration cache problems with other types:
15-
// https://github.com/gradle/gradle/issues/24040
16-
credentials(PasswordCredentials::class)
17-
}
18-
}
199
publications.withType<MavenPublication>().configureEach {
2010
pom {
2111
name = project.name
@@ -44,7 +34,6 @@ publishing {
4434
}
4535
}
4636

47-
4837
signPublicationIfKeyPresent(project, this)
4938
}
5039

0 commit comments

Comments
 (0)