@@ -21,14 +21,19 @@ def isReleaseBuild() {
2121 return VERSION_NAME . contains(" SNAPSHOT" ) == false
2222}
2323
24+ def getRepositoryUrl () {
25+ return hasProperty(' REPOSITORY_URL' ) ? RELEASE_REPOSITORY_URL
26+ : " https://ossrh-staging-api.central.sonatype.com"
27+ }
28+
2429def getReleaseRepositoryUrl () {
2530 return hasProperty(' RELEASE_REPOSITORY_URL' ) ? RELEASE_REPOSITORY_URL
26- : " https://oss. sonatype.org /service/local/staging/deploy/maven2/"
31+ : " https://ossrh-staging-api.central. sonatype.com /service/local/staging/deploy/maven2/"
2732}
2833
2934def getSnapshotRepositoryUrl () {
3035 return hasProperty(' SNAPSHOT_REPOSITORY_URL' ) ? SNAPSHOT_REPOSITORY_URL
31- : " https://oss. sonatype.org /content/repositories/snapshots/"
36+ : " https://ossrh-staging-api.central. sonatype.com /content/repositories/snapshots/"
3237}
3338
3439def getRepositoryUsername () {
@@ -148,3 +153,25 @@ afterEvaluate {
148153 sign publishing. publications
149154 }
150155}
156+
157+ tasks. named(' publish' ) {
158+ finalizedBy tasks. named(' postRelease' )
159+ }
160+
161+ tasks. register(' postRelease' ) {
162+ doLast {
163+ def username = getRepositoryUsername()
164+ def password = getRepositoryPassword()
165+ def url = getRepositoryUrl() + " /manual/upload/defaultRepository/com.qiniu"
166+ // 发送 POST 请求,使发布文件能在 central sonatype 中显示
167+ def connection = new URL (url). openConnection() as HttpURLConnection
168+ connection. setRequestMethod(" POST" )
169+ connection. setRequestProperty(" Content-Type" , " application/x-www-form-urlencoded" )
170+ connection. setRequestProperty(' Authorization' , ' Basic ' + " ${ username} :${ password} " . bytes. encodeBase64(). toString())
171+ connection. doOutput = false
172+
173+ // 读取响应
174+ def response = connection. inputStream. text
175+ println " POST 响应: ${ response} "
176+ }
177+ }
0 commit comments