Skip to content

Commit

Permalink
Allow publishing to a pre-defined staging repository (#3562)
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnatBeresnev committed Apr 22, 2024
1 parent 4f5a650 commit e22c40b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion build-logic/src/main/kotlin/dokkabuild.publish-base.gradle.kts
@@ -1,3 +1,5 @@
import java.net.URI

/*
* Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
Expand All @@ -13,7 +15,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 @@ -68,6 +70,22 @@ publishing {
}
}

/**
* Due to Gradle running publishing tasks in parallel, multiple staging repositories
* can be created within a couple of seconds with all artifact files scattered throughout them.
*
* While Gradle's parallelism can be disabled, the simplest and most reliable option is
* to just publish to a pre-defined staging repository.
*/
fun mavenCentralRepositoryUri(): URI {
val repositoryId: String? = System.getenv("DOKKA_MVN_CENTRAL_REPOSITORY_ID")
return if (repositoryId.isNullOrBlank()) {
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 e22c40b

Please sign in to comment.