@@ -107,20 +107,57 @@ tasks.register("publishSnapshotToCentral") {
107107
108108 // Upload each artifact file
109109 artifactDir. eachFile { file ->
110- if (file. isFile() && ! file. name. endsWith(' .sha1' ) && ! file. name. endsWith(' .md5' ) &&
110+ if (file. isFile() && ! file. name. endsWith(' .sha1' ) && ! file. name. endsWith(' .md5' ) &&
111111 ! file. name. endsWith(' .sha256' ) && ! file. name. endsWith(' .sha512' )) {
112112 println " Uploading ${ file.name} to Sonatype Central snapshots..."
113113
114- def connection = new URL (" https://central.sonatype.com/api/v1/publisher/snapshots/${ project.group} /${ project.name} /${ project.version} /${ file.name} " ). openConnection()
115- connection. setRequestMethod(" PUT" )
114+ // Use the correct Sonatype Central snapshot API endpoint
115+ def uploadUrl = " https://central.sonatype.com/api/v1/publisher/snapshots"
116+ def connection = new URL (uploadUrl). openConnection()
117+ connection. setRequestMethod(" POST" )
116118 connection. setRequestProperty(" Authorization" , " Basic ${ encodedCredentials} " )
117- connection. setRequestProperty(" Content-Type" , " application/octet-stream " )
119+ connection. setRequestProperty(" Content-Type" , " multipart/form-data " )
118120 connection. setDoOutput(true )
119121
120- // Upload file content
122+ // Set up multipart form data for snapshot upload
123+ def boundary = " ----WebKitFormBoundary" + System . currentTimeMillis()
124+ connection. setRequestProperty(" Content-Type" , " multipart/form-data; boundary=" + boundary)
125+
126+ def outputStream = connection. getOutputStream()
127+ def writer = new PrintWriter (new OutputStreamWriter (outputStream, " UTF-8" ), true )
128+
129+ // Add metadata fields
130+ writer. append(" --" + boundary). append(" \r\n " )
131+ writer. append(" Content-Disposition: form-data; name=\" groupId\" " ). append(" \r\n " )
132+ writer. append(" \r\n " )
133+ writer. append(project. group. toString()). append(" \r\n " )
134+
135+ writer. append(" --" + boundary). append(" \r\n " )
136+ writer. append(" Content-Disposition: form-data; name=\" artifactId\" " ). append(" \r\n " )
137+ writer. append(" \r\n " )
138+ writer. append(project. name). append(" \r\n " )
139+
140+ writer. append(" --" + boundary). append(" \r\n " )
141+ writer. append(" Content-Disposition: form-data; name=\" version\" " ). append(" \r\n " )
142+ writer. append(" \r\n " )
143+ writer. append(project. version. toString()). append(" \r\n " )
144+
145+ // Add file part
146+ writer. append(" --" + boundary). append(" \r\n " )
147+ writer. append(" Content-Disposition: form-data; name=\" file\" ; filename=\" " + file. name + " \" " ). append(" \r\n " )
148+ writer. append(" Content-Type" : " application/octet-stream" ). append(" \r\n " )
149+ writer. append(" \r\n " )
150+ writer. flush()
151+
152+ // Write file content
121153 file. withInputStream { inputStream ->
122- connection . outputStream << inputStream
154+ outputStream << inputStream
123155 }
156+ outputStream. flush()
157+
158+ writer. append(" \r\n " )
159+ writer. append(" --" + boundary + " --" ). append(" \r\n " )
160+ writer. close()
124161
125162 def responseCode = connection. responseCode
126163 if (responseCode >= 200 && responseCode < 300 ) {
0 commit comments