Skip to content

Commit 9f28820

Browse files
committed
Migrated to Central Portal publishing
1 parent 4a3d34c commit 9f28820

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed
Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
publishing {
22
repositories {
33
maven {
4-
name = "ossrh"
5-
url = "https://s01.oss.sonatype.org/" + (project.maven_version.endsWith("SNAPSHOT") ? "content/repositories/snapshots/" : "service/local/staging/deploy/maven2/")
4+
name = "central"
5+
if (project.maven_version.endsWith("SNAPSHOT")) {
6+
url = "https://central.sonatype.com/repository/maven-snapshots"
7+
} else {
8+
url = "https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2"
9+
}
610

711
credentials(PasswordCredentials)
812
authentication {
@@ -11,3 +15,21 @@ publishing {
1115
}
1216
}
1317
}
18+
19+
tasks.withType(PublishToMavenRepository).configureEach {
20+
if (it.name.endsWith("ToCentralRepository")) {
21+
def centralUsername = providers.gradleProperty("centralUsername")
22+
def centralPassword = providers.gradleProperty("centralPassword")
23+
def mavenGroup = it.publication.groupId
24+
it.doLast {
25+
def connection = URI.create("https://ossrh-staging-api.central.sonatype.com/manual/upload/defaultRepository/$mavenGroup").toURL().openConnection() as HttpURLConnection
26+
connection.setRequestMethod("POST")
27+
connection.setRequestProperty("Authorization", "Basic " + "${centralUsername.get()}:${centralPassword.get()}".bytes.encodeBase64().toString())
28+
connection.connect()
29+
if (connection.getResponseCode() != 200) {
30+
throw new GradleException("Failed to close staging repository: ${connection.getResponseCode()} ${connection.getResponseMessage()}")
31+
}
32+
connection.disconnect()
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)