Skip to content

Commit 13334c7

Browse files
author
闫茂源
committed
feat: update sonatype api
1 parent 4fcfc45 commit 13334c7

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

build.gradle

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,21 @@ allprojects {
99
options.encoding = 'UTF-8'
1010
}
1111
}
12+
}
13+
14+
// Notify Sonatype upload after all publish tasks are completed
15+
gradle.projectsEvaluated {
16+
// get publish tasks from all subprojects
17+
def publishTasks = subprojects.collect { subproject ->
18+
subproject.tasks.matching { it.name.startsWith('publish') && it.name.endsWith('PublicationToOSSRHRepository') }
19+
}.flatten()
20+
21+
// register a new task to trigger Sonatype upload
22+
tasks.register('allPublishToOSSRH') {
23+
group = 'publishing'
24+
description = 'Publish all modules to OSSRH and notify Sonatype'
25+
26+
dependsOn publishTasks
27+
finalizedBy sonatypeUpload
28+
}
1229
}

sonatype-api.gradle

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ def getSonatypeCredentials() {
1111
return "Bearer ${auth}"
1212
}
1313

14-
// 公共方法:发送 HTTP 请求
1514
def callSonatypeApi(String method, String url, Closure responseHandler = null) {
1615
try {
1716
def connection = new URL("https://ossrh-staging-api.central.sonatype.com" + url).openConnection() as HttpURLConnection
@@ -96,12 +95,10 @@ tasks.register('sonatypeUpload') {
9695
}
9796
}
9897

99-
// 上传到指定仓库
100-
tasks.register('sonatypeUploadToRepository') {
98+
tasks.register('sonatypeUploadRepository') {
10199
group = 'publishing'
102100
description = 'Upload to a specific Sonatype repository (requires -PrepositoryKey=<key>)'
103101

104-
// 检查是否提供了 repositoryKey 参数
105102
onlyIf {
106103
if (!project.hasProperty('repositoryKey')) {
107104
throw new GradleException('Repository key is required. Use -PrepositoryKey=<key>')
@@ -128,12 +125,10 @@ tasks.register('sonatypeUploadToRepository') {
128125
}
129126
}
130127

131-
// 删除指定仓库
132128
tasks.register('sonatypeDropRepository') {
133129
group = 'publishing'
134130
description = 'Drop a specific Sonatype repository (requires -PrepositoryKey=<key>)'
135131

136-
// 检查是否提供了 repositoryKey 参数
137132
onlyIf {
138133
if (!project.hasProperty('repositoryKey')) {
139134
throw new GradleException('Repository key is required. Use -PrepositoryKey=<key>')

0 commit comments

Comments
 (0)