@@ -21,14 +21,19 @@ def isReleaseBuild() {
21
21
return VERSION_NAME . contains(" SNAPSHOT" ) == false
22
22
}
23
23
24
+ def getRepositoryUrl () {
25
+ return hasProperty(' REPOSITORY_URL' ) ? RELEASE_REPOSITORY_URL
26
+ : " https://ossrh-staging-api.central.sonatype.com"
27
+ }
28
+
24
29
def getReleaseRepositoryUrl () {
25
30
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/"
27
32
}
28
33
29
34
def getSnapshotRepositoryUrl () {
30
35
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/"
32
37
}
33
38
34
39
def getRepositoryUsername () {
@@ -148,3 +153,25 @@ afterEvaluate {
148
153
sign publishing. publications
149
154
}
150
155
}
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