@@ -105,16 +105,6 @@ test {
105105}
106106
107107publishing {
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+
179202signing {
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