Skip to content

Commit

Permalink
Allow publishing to a pre-defined staging repository
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnatBeresnev committed Feb 29, 2024
1 parent 9d11031 commit ff47f23
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion build-logic/src/main/kotlin/dokkabuild.publish-base.gradle.kts
@@ -1,3 +1,5 @@
import java.net.URI

/*
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
Expand All @@ -11,7 +13,7 @@ publishing {
repositories {
maven {
name = "mavenCentral"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
url = mavenCentralRepositoryUri()
credentials {
username = System.getenv("DOKKA_SONATYPE_USER")
password = System.getenv("DOKKA_SONATYPE_PASSWORD")
Expand Down Expand Up @@ -73,6 +75,20 @@ publishing {
}
}

/**
* Due to Gradle running publishing tasks in parallel, multiple staging repositories
* can be created within a couple of seconds with artifact files scattered throughout.
* The safest and most stable option is to publish to a pre-defined staging repository.
*/
fun mavenCentralRepositoryUri(): URI {
val repositoryId: String? = System.getenv("DOKKA_MVN_CENTRAL_REPOSITORY_ID")
return if (repositoryId == null) {
URI("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
} else {
URI("https://oss.sonatype.org/service/local/staging/deployByRepositoryId/$repositoryId")
}
}

signing {
useInMemoryPgpKeys(
System.getenv("DOKKA_SIGN_KEY_ID")?.takeIf(String::isNotBlank),
Expand Down

0 comments on commit ff47f23

Please sign in to comment.