Skip to content

Commit 6812a18

Browse files
committed
Revert back to mavenPublish publication of snapshots as using bundles does not appear to be supported.
1 parent 1815e05 commit 6812a18

File tree

3 files changed

+29
-20
lines changed

3 files changed

+29
-20
lines changed

.github/workflows/publish-snapshot.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ jobs:
4141
path: |
4242
**/build/reports/
4343
**/build/test-results/
44+
- name: Build
45+
run: ./gradlew assemble -PforceSnapshot=true -PexcludeSchema -Pnative.deploy=all
46+
shell: bash
4447
- name: Upload
45-
run: ./gradlew publishToSonatype -PforceSnapshot=true -PexcludeSchema -Possrh.username='${{ secrets.OSSRH_USERNAME }}' -Possrh.password='${{ secrets.OSSRH_PASSWORD }}' -Pnative.deploy=all --stacktrace
48+
# run: ./gradlew publishToSonatype -PforceSnapshot=true -PexcludeSchema -Possrh.username='${{ secrets.OSSRH_USERNAME }}' -Possrh.password='${{ secrets.OSSRH_PASSWORD }}' -Pnative.deploy=all --stacktrace
49+
run: ./gradlew publishAllPublicationsToMavenSnapshotRepository -PforceSnapshot=true -PexcludeSchema -Possrh.username='${{ secrets.OSSRH_USERNAME }}' -Possrh.password='${{ secrets.OSSRH_PASSWORD }}' -Pnative.deploy=all
4650
shell: bash

project-plugins/src/main/kotlin/io/github/xmlutil/plugin/PublishToSonatypeTask.kt

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,30 @@ abstract class PublishToSonatypeTask() : DefaultTask() {
5151
val encoded = String(Base64.getEncoder().encode("$username:$password".toByteArray()), Charsets.US_ASCII)
5252

5353
val client = HttpClientBuilder.create().build()
54-
val versionName: String = when {
54+
val deploymentType: String
55+
val versionName: String
56+
val apiBase: String
57+
58+
when {
5559
project.isSnapshot -> {
5660
if ("SNAPSHOT" !in project.version.toString()) {
5761
throw IllegalStateException("Attempting to publish a non-snapshot version as a snapshot: ${project.version}")
5862
}
59-
"${project.version}-${LocalDateTime.now().format(TIMESTAMP_FORMATTER)}"
63+
versionName = "${project.version}-${LocalDateTime.now().format(TIMESTAMP_FORMATTER)}"
64+
apiBase = "https://central.sonatype.com/repository/maven-snapshots"
65+
// deploymentType = "AUTOMATIC"
66+
deploymentType = "USER_MANAGED"
6067
}
6168

62-
else -> project.version.toString()
69+
else -> {
70+
versionName = project.version.toString()
71+
deploymentType = "USER_MANAGED"
72+
apiBase = "https://central.sonatype.com"
73+
}
6374
}
6475

6576
val deploymentName = URLEncoder.encode("XMLUtil deployment $versionName", Charsets.UTF_8)
66-
val deploymentType = when {
67-
project.isSnapshot -> "AUTOMATIC"
68-
else -> "USER_MANAGED"
69-
}
70-
val post = HttpPost("https://central.sonatype.com/api/v1/publisher/upload?name=$deploymentName&publishingType=$deploymentType")
77+
val post = HttpPost("$apiBase/api/v1/publisher/upload?name=$deploymentName&publishingType=$deploymentType")
7178
post.addHeader("Authorization", "Bearer $encoded")
7279

7380
post.entity = MultipartEntityBuilder.create()

project-plugins/src/main/kotlin/net/devrieze/gradle/ext/publishing.kt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024-2025.
2+
* Copyright (c) 2024-2026.
33
*
44
* This file is part of xmlutil.
55
*
@@ -20,6 +20,7 @@
2020

2121
package net.devrieze.gradle.ext
2222

23+
import io.github.xmlutil.plugin.isSnapshot
2324
import org.gradle.api.Project
2425
import org.gradle.api.Task
2526
import org.gradle.api.publish.PublishingExtension
@@ -46,23 +47,20 @@ fun Project.doPublish(
4647

4748
configure<PublishingExtension> {
4849
this.repositories {
49-
when {
50-
/*
51-
isSnapshot -> maven {
50+
if (isSnapshot) {
51+
maven {
5252
name = "mavenSnapshot"
5353
url = uri("https://central.sonatype.com/repository/maven-snapshots/")
5454
credentials {
5555
username = project.findProperty("ossrh.username") as String?
5656
password = project.findProperty("ossrh.password") as String?
5757
}
5858
}
59-
*/
60-
61-
else -> maven {
62-
name = "projectLocal"
59+
}
60+
maven {
61+
name = "projectLocal"
6362

64-
setUrl(project.layout.buildDirectory.dir("project-local-repository").map { it.asFile.toURI() })
65-
}
63+
setUrl(rootProject.layout.buildDirectory.dir("project-local-repository").map { it.asFile.toURI() })
6664
}
6765

6866
}
@@ -165,7 +163,7 @@ fun Project.doPublish(
165163
if (isEnabled) {
166164

167165
if (repository?.name == "projectLocal") {
168-
val repositoryDir = project.layout.buildDirectory.dir("project-local-repository")
166+
val repositoryDir = rootProject.layout.buildDirectory.dir("project-local-repository")
169167
if (repositoryDir.isPresent) {
170168
repositoryDir.get().asFile.deleteRecursively()
171169
}

0 commit comments

Comments
 (0)