Skip to content

Support a new publication scheme #3038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
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)
}