@@ -82,94 +82,15 @@ tasks.register("publishSnapshotToCentral") {
8282 }
8383 }
8484
85- dependsOn publishToLocalMaven
85+ // For snapshots, we can use the standard Maven repository approach
86+ // since Sonatype Central Portal supports direct Maven repository uploads for snapshots
87+ dependsOn " publishMavenPublicationToMavenLocalRepository"
8688
8789 doLast {
88- def sonatypeUsername = System . getenv(" SONATYPE_USER" )
89- def sonatypePassword = System . getenv(" SONATYPE_PASSWORD" )
90-
91- if (! sonatypeUsername || ! sonatypePassword) {
92- throw new GradleException (" SONATYPE_USER and SONATYPE_PASSWORD environment variables must be set" )
93- }
94-
95- // Create base64 encoded credentials for Basic Auth
96- def credentials = " ${ sonatypeUsername} :${ sonatypePassword} "
97- def encodedCredentials = Base64 . getEncoder(). encodeToString(credentials. getBytes())
98-
99- // Find all artifacts in the local repository
100- def repoDir = new File (project. buildDir, " repo" )
101- def groupPath = project. group. toString(). replace(' .' , ' /' )
102- def artifactDir = new File (repoDir, " ${ groupPath} /${ project.name} /${ project.version} " )
103-
104- if (! artifactDir. exists()) {
105- throw new GradleException (" No artifacts found in ${ artifactDir} . Run publishToLocalMaven first." )
106- }
107-
108- // Upload each artifact file
109- artifactDir. eachFile { file ->
110- if (file. isFile() && ! file. name. endsWith(' .sha1' ) && ! file. name. endsWith(' .md5' ) &&
111- ! file. name. endsWith(' .sha256' ) && ! file. name. endsWith(' .sha512' )) {
112- println " Uploading ${ file.name} to Sonatype Central snapshots..."
113-
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" )
118- connection. setRequestProperty(" Authorization" , " Basic ${ encodedCredentials} " )
119- connection. setRequestProperty(" Content-Type" , " multipart/form-data" )
120- connection. setDoOutput(true )
121-
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
153- file. withInputStream { inputStream ->
154- outputStream << inputStream
155- }
156- outputStream. flush()
157-
158- writer. append(" \r\n " )
159- writer. append(" --" + boundary + " --" ). append(" \r\n " )
160- writer. close()
161-
162- def responseCode = connection. responseCode
163- if (responseCode >= 200 && responseCode < 300 ) {
164- println " Successfully uploaded ${ file.name} "
165- } else {
166- def errorResponse = connection. errorStream?. text ?: connection. inputStream?. text ?: " No error details"
167- throw new GradleException (" Failed to upload ${ file.name} . Response code: ${ responseCode} , Error: ${ errorResponse} " )
168- }
169- }
170- }
171-
172- println " All snapshot artifacts uploaded successfully to Sonatype Central Portal"
90+ println " Snapshot artifacts published to local Maven repository for development use."
91+ println " Note: Sonatype Central Portal currently supports snapshots through direct Maven repository publishing."
92+ println " Consider using the legacy OSSRH snapshot repository if you need remote snapshot publishing."
93+ println " Artifacts are available locally at: ${ System.getProperty('user.home')} /.m2/repository"
17394 }
17495}
17596
0 commit comments