Skip to content

Commit 42c4569

Browse files
committed
fix: publishing
1 parent ac64e49 commit 42c4569

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish to Maven Central
1+
name: Publish to Maven Central Portal
22
on:
33
release:
44
types: [published]
@@ -44,7 +44,7 @@ jobs:
4444
MAVEN_USERNAME: ${{secrets.MAVEN_USERNAME}}
4545
MAVEN_SECRET: ${{secrets.MAVEN_SECRET}}
4646
run: |
47-
gradle publishMavenJavaPublicationToCentralRepository \
47+
gradle uploadToCentralPortal \
4848
-PsigningKey="${SIGNING_KEY}" \
4949
-PsigningPassword="${SIGNING_PASSWORD}" \
5050
--info

build.gradle

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,6 @@ test {
105105
}
106106

107107
publishing {
108-
repositories {
109-
maven {
110-
name = "central"
111-
url = "https://central.sonatype.com/api/v1/publisher/upload"
112-
credentials {
113-
username = System.getenv("MAVEN_USERNAME")
114-
password = System.getenv("MAVEN_SECRET")
115-
}
116-
}
117-
}
118108
publications {
119109
mavenJava(MavenPublication) {
120110
from components.java
@@ -176,8 +166,41 @@ publishing {
176166
}
177167
}
178168

169+
// Task to create a bundle for Central Portal upload
170+
task createCentralBundle(type: Zip) {
171+
dependsOn 'publishToMavenLocal'
172+
archiveBaseName = 'central-bundle'
173+
archiveVersion = project.version
174+
archiveExtension = 'zip'
175+
176+
def localRepo = repositories.mavenLocal().url
177+
def groupPath = project.group.toString().replace('.', '/')
178+
def artifactPath = "${groupPath}/${base.archivesName.get()}/${project.version}"
179+
180+
from("${localRepo}/${artifactPath}") {
181+
include '**/*'
182+
}
183+
184+
destinationDirectory = file("${buildDir}/central")
185+
}
186+
187+
// Task to upload bundle to Central Portal
188+
task uploadToCentralPortal(type: Exec) {
189+
dependsOn 'createCentralBundle'
190+
191+
def username = System.getenv("MAVEN_USERNAME")
192+
def password = System.getenv("MAVEN_SECRET")
193+
def bundleFile = "${buildDir}/central/central-bundle-${project.version}.zip"
194+
195+
commandLine 'curl', '-X', 'POST',
196+
'-H', 'Content-Type: multipart/form-data',
197+
'-F', "bundle=@${bundleFile}",
198+
'-u', "${username}:${password}",
199+
'https://central.sonatype.com/api/v1/publisher/upload'
200+
}
201+
179202
signing {
180-
required { gradle.taskGraph.hasTask("publishMavenJavaPublicationToCentralRepository") }
203+
required { gradle.taskGraph.hasTask("uploadToCentralPortal") }
181204
def signingKey = findProperty("signingKey")
182205
def signingPassword = findProperty("signingPassword")
183206
if (signingKey && signingPassword) {

0 commit comments

Comments
 (0)