Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions buildSrc/src/main/kotlin/publishing-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ val testRepositoryDir = project.layout.buildDirectory.dir("testRepository")

publishing {
repositories {
addSonatypeRepository()
addPublishingRepositoryIfPresent()

/**
* Maven repository in build directory to check published artifacts.
Expand Down Expand Up @@ -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)
}