Skip to content
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

Support publishing snapshot releases to Central Portal #894

Merged
merged 2 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
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
10 changes: 3 additions & 7 deletions docs/central.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,6 @@ lQdGBF4jUfwBEACblZV4uBViHcYLOb2280tEpr64iB9b6YRkWil3EODiiLd9JS3V...9pip+B1QLwEdL

## Publishing snapshots

!!! warning "Central Portal"

Publishing snapshots is not supported when using the Central Portal (central.sonatype.com).


Snapshots can be published by setting the version to something ending with `-SNAPSHOT`
and then running the following Gradle task:

Expand All @@ -290,8 +285,9 @@ and then running the following Gradle task:
```

The snapshot will be automatically available in Sonatype's
[snapshot repository](https://oss.sonatype.org/content/repositories/snapshots/) (or the
[S01 snapshot repository](https://s01.oss.sonatype.org/content/repositories/snapshots/)) directly after the
[snapshot repository](https://oss.sonatype.org/content/repositories/snapshots/), or the
[S01 snapshot repository](https://s01.oss.sonatype.org/content/repositories/snapshots/), or the
[Central Portal snapshot repository](https://central.sonatype.com/repository/maven-snapshots/) directly after the
task finished.

Signing is not required for snapshot builds, but if the configuration is present the build
Expand Down
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
Loading