diff --git a/buildSrc/src/main/kotlin/publishing-conventions.gradle.kts b/buildSrc/src/main/kotlin/publishing-conventions.gradle.kts index 82a92963d..4436677f3 100644 --- a/buildSrc/src/main/kotlin/publishing-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/publishing-conventions.gradle.kts @@ -92,7 +92,7 @@ val testRepositoryDir = project.layout.buildDirectory.dir("testRepository") publishing { repositories { - addSonatypeRepository() + addPublishingRepositoryIfPresent() /** * Maven repository in build directory to check published artifacts. @@ -232,26 +232,21 @@ fun MavenPublication.signPublicationIfKeyPresent() { } } -fun RepositoryHandler.addSonatypeRepository() { - maven { - url = mavenRepositoryUri() - credentials { - username = getSensitiveProperty("libs.sonatype.user") - password = getSensitiveProperty("libs.sonatype.password") +// Artifacts are published to an intermediate repo (libs.repo.url) first, +// and then deployed to the central portal. +fun RepositoryHandler.addPublishingRepositoryIfPresent() { + val repositoryUrl = getSensitiveProperty("libs.repo.url") + if (!repositoryUrl.isNullOrBlank()) { + maven { + url = uri(repositoryUrl) + credentials { + username = getSensitiveProperty("libs.repo.user") + password = getSensitiveProperty("libs.repo.password") + } } } } -fun mavenRepositoryUri(): URI { - // TODO -SNAPSHOT detection can be made here as well - val repositoryId: String? = System.getenv("libs.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") - } -} - fun getSensitiveProperty(name: String): String? { return findProperty(name) as? String ?: System.getenv(name) }