Skip to content

Commit ff47f23

Browse files
committed
Allow publishing to a pre-defined staging repository
1 parent 9d11031 commit ff47f23

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

build-logic/src/main/kotlin/dokkabuild.publish-base.gradle.kts

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import java.net.URI
2+
13
/*
24
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
35
*/
@@ -11,7 +13,7 @@ publishing {
1113
repositories {
1214
maven {
1315
name = "mavenCentral"
14-
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
16+
url = mavenCentralRepositoryUri()
1517
credentials {
1618
username = System.getenv("DOKKA_SONATYPE_USER")
1719
password = System.getenv("DOKKA_SONATYPE_PASSWORD")
@@ -73,6 +75,20 @@ publishing {
7375
}
7476
}
7577

78+
/**
79+
* Due to Gradle running publishing tasks in parallel, multiple staging repositories
80+
* can be created within a couple of seconds with artifact files scattered throughout.
81+
* The safest and most stable option is to publish to a pre-defined staging repository.
82+
*/
83+
fun mavenCentralRepositoryUri(): URI {
84+
val repositoryId: String? = System.getenv("DOKKA_MVN_CENTRAL_REPOSITORY_ID")
85+
return if (repositoryId == null) {
86+
URI("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
87+
} else {
88+
URI("https://oss.sonatype.org/service/local/staging/deployByRepositoryId/$repositoryId")
89+
}
90+
}
91+
7692
signing {
7793
useInMemoryPgpKeys(
7894
System.getenv("DOKKA_SIGN_KEY_ID")?.takeIf(String::isNotBlank),

0 commit comments

Comments
 (0)