diff --git a/plugin/src/main/kotlin/com/vanniktech/maven/publish/MavenPublishBaseExtension.kt b/plugin/src/main/kotlin/com/vanniktech/maven/publish/MavenPublishBaseExtension.kt index bb638488..1ca3d735 100644 --- a/plugin/src/main/kotlin/com/vanniktech/maven/publish/MavenPublishBaseExtension.kt +++ b/plugin/src/main/kotlin/com/vanniktech/maven/publish/MavenPublishBaseExtension.kt @@ -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 @@ -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, @@ -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) } } diff --git a/plugin/src/main/kotlin/com/vanniktech/maven/publish/sonatype/SonatypeRepositoryBuildService.kt b/plugin/src/main/kotlin/com/vanniktech/maven/publish/sonatype/SonatypeRepositoryBuildService.kt index 45086030..836e691a 100644 --- a/plugin/src/main/kotlin/com/vanniktech/maven/publish/sonatype/SonatypeRepositoryBuildService.kt +++ b/plugin/src/main/kotlin/com/vanniktech/maven/publish/sonatype/SonatypeRepositoryBuildService.kt @@ -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")