@@ -217,13 +217,15 @@ publishing {
217217 }
218218 repositories {
219219 maven {
220- name = " OSSRH"
221- def releasesRepoUrl = " https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
222- def snapshotsRepoUrl = " https://s01.oss.sonatype.org/content/repositories/snapshots/"
223- url = version. endsWith(' SNAPSHOT' ) ? snapshotsRepoUrl : releasesRepoUrl
220+ name = ' ossrh-staging-api'
221+ val stagingUrl =
222+ " https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"
223+ val snapshotsUrl =
224+ " https://central.sonatype.com/repository/maven-snapshots/"
225+ url = uri(if (version. toString(). endsWith(" -SNAPSHOT" )) snapshotsUrl else stagingUrl)
224226 credentials {
225- username = System . getenv(" MAVEN_USERNAME " )
226- password = System . getenv(" MAVEN_PASSWORD " )
227+ username = System . getenv(" OSSRH_USER " ]
228+ password = System . getenv(" OSSRH_PASS " ]
227229 }
228230 }
229231 maven {
@@ -275,3 +277,33 @@ idea {
275277 }
276278 }
277279}
280+
281+
282+ import java.net.http.HttpClient
283+ import java.net.http.HttpRequest
284+ import java.net.http.HttpResponse
285+ import java.util.Base64
286+
287+ tasks. register(" publishToMavenCentral" ) {
288+ group = " publishing"
289+ description = " Publishes all Maven publications produced by this project to Maven Central."
290+ dependsOn(" publish" )
291+ doLast {
292+ val username = System . getenv(" OSSRH_USER" ]
293+ val password = System . getenv(" OSSRH_PASS" ]
294+ val namespace = " org.polypheny"
295+ val token = Base64 . getEncoder(). encodeToString(" $username :$password " . encodeToByteArray())
296+ val client = HttpClient . newHttpClient()
297+ val request = HttpRequest . newBuilder()
298+ .uri(uri(" https://ossrh-staging-api.central.sonatype.com/manual/upload/defaultRepository/$namespace " ))
299+ .header(" Authorization" , " Bearer $token " )
300+ .POST (HttpRequest.BodyPublishers . noBody())
301+ .build()
302+ val response = client. send(request, HttpResponse.BodyHandlers . ofString())
303+ if (response. statusCode() < 400 ) {
304+ logger. info(response. body())
305+ } else {
306+ logger. error(response. body())
307+ }
308+ }
309+ }
0 commit comments