Skip to content

Commit

Permalink
support publishing snapshot releases to central portal (vanniktech#891)
Browse files Browse the repository at this point in the history
  • Loading branch information
solrudev committed Jan 18, 2025
1 parent 1763084 commit 35212ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import javax.inject.Inject
import org.gradle.api.Action
import org.gradle.api.Incubating
import org.gradle.api.Project
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
import org.gradle.api.credentials.PasswordCredentials
import org.gradle.api.provider.Property
import org.gradle.api.publish.maven.MavenPom
Expand Down Expand Up @@ -59,10 +60,12 @@ abstract class MavenPublishBaseExtension @Inject constructor(
sonatypeHost.set(host)
sonatypeHost.finalizeValue()

val versionIsSnapshot = version.map { it.endsWith("-SNAPSHOT") }

val buildService = project.registerSonatypeRepositoryBuildService(
sonatypeHost = sonatypeHost,
groupId = groupId,
versionIsSnapshot = version.map { it.endsWith("-SNAPSHOT") },
versionIsSnapshot = versionIsSnapshot,
repositoryUsername = project.providers.gradleProperty("mavenCentralUsername"),
repositoryPassword = project.providers.gradleProperty("mavenCentralPassword"),
automaticRelease = automaticRelease,
Expand All @@ -74,7 +77,10 @@ abstract class MavenPublishBaseExtension @Inject constructor(
project.gradlePublishing.repositories.maven { repo ->
repo.name = "mavenCentral"
repo.setUrl(buildService.map { it.publishingUrl() })
if (!host.isCentralPortal) {
}

project.gradlePublishing.repositories.withType(MavenArtifactRepository::class.java) { repo ->
if (repo.name == "mavenCentral" && (!host.isCentralPortal || versionIsSnapshot.get())) {
repo.credentials(PasswordCredentials::class.java)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ internal abstract class SonatypeRepositoryBuildService :
}

val host = parameters.sonatypeHost.get()
require(!host.isCentralPortal) {
"Snapshots are not supported when publishing through the central portal."
if (host.isCentralPortal) {
"${host.rootUrl}/repository/maven-snapshots/"
} else {
"${host.rootUrl}/content/repositories/snapshots/"
}

"${host.rootUrl}/content/repositories/snapshots/"
} else {
val stagingRepositoryId = requireNotNull(uploadId) {
@Suppress("UnstableApiUsage")
Expand Down

0 comments on commit 35212ae

Please sign in to comment.