@@ -99,39 +99,49 @@ publishing {
99
99
}
100
100
}
101
101
102
-
103
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104
- // Signing
105
-
106
- def signPublicationsTask = tasks. register(' signPublications' ) {
107
- description " Grouping task which executes all Sign tasks"
108
-
109
- dependsOn tasks. withType( Sign )
102
+ tasks. withType(PublishToMavenLocal ). configureEach {
103
+ doFirst {
104
+ logger. lifecycle(" PublishToMavenLocal ({})" , publication. name)
105
+ logger. lifecycle(" - {} : {} : {} " , publication. groupId, publication. artifactId, publication. pom. packaging)
106
+ logger. lifecycle(" - artifacts ({})..." , publication. artifacts. size())
107
+ publication. artifacts. forEach {
108
+ logger. lifecycle(" - artifact ({}) : {} ({})" , it. classifier, it. file, it. file. size())
109
+ }
110
+ }
110
111
}
111
112
112
- tasks. named( " publishPublishedArtifactsPublicationToSonatypeRepository" ) {
113
- // publishing depends on signing
114
- dependsOn signPublicationsTask
113
+ tasks. withType(PublishToMavenRepository ). configureEach {
114
+ doFirst {
115
+ logger. lifecycle(" PublishToMavenRepository ({} : {})" , publication. name, repository. name)
116
+ logger. lifecycle(" - {} : {} : {} " , publication. groupId, publication. artifactId, publication. pom. packaging)
117
+ logger. lifecycle(" - artifacts ({})..." , publication. artifacts. size())
118
+ publication. artifacts. forEach {
119
+ logger. lifecycle(" - artifact ({}) : {} ({})" , it. classifier, it. file, it. file. size())
120
+ }
121
+ }
115
122
}
116
123
117
- tasks. register(' sign' ) {
118
- description " Pseudonym for :signPublications"
119
- dependsOn signPublicationsTask
120
- }
124
+
125
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
126
+ // Signing
127
+
128
+ def signingKey = resolveSigningKey()
129
+ def signingPassphrase = resolveSigningPassphrase()
121
130
122
131
var signingExtension = project. getExtensions(). getByType(SigningExtension ) as SigningExtension
123
132
signingExtension. sign publishing. publications. publishedArtifacts
133
+ signingExtension. useInMemoryPgpKeys(signingKey, signingPassphrase)
134
+
124
135
125
136
gradle. taskGraph. whenReady { TaskExecutionGraph graph ->
126
- boolean wasSigningRequested = false
137
+ // are we publishing to OSSRH?
127
138
boolean wasPublishingRequested = false
128
139
129
140
graph. allTasks. each {task ->
130
- if ( task instanceof Sign ) {
131
- wasSigningRequested = true
132
- }
133
- else if ( task instanceof PublishToMavenRepository ) {
134
- wasPublishingRequested = true
141
+ if ( task instanceof PublishToMavenRepository ) {
142
+ if ( " sonatype" == task. repository. name ) {
143
+ wasPublishingRequested = true
144
+ }
135
145
}
136
146
}
137
147
@@ -142,20 +152,9 @@ gradle.taskGraph.whenReady { TaskExecutionGraph graph ->
142
152
throw new RuntimeException ( " Cannot perform publishing to OSSRH without credentials." )
143
153
}
144
154
logger. lifecycle " Publishing {} : {} : {}" , project. group, project. name, project. version
145
- }
146
-
147
- if ( wasSigningRequested || wasPublishingRequested ) {
148
- // signing was explicitly requested and/or we are publishing to Sonatype OSSRH
149
- // - we need the signing to happen
150
155
signingExtension. required = true
151
-
152
- var signingKey = resolveSigningKey()
153
- var signingPassword = resolveSigningPassphrase()
154
- signingExtension. useInMemoryPgpKeys( signingKey, signingPassword )
155
156
}
156
- else {
157
- // signing was not explicitly requested and we are not publishing to OSSRH,
158
- // - disable all Sign tasks
157
+ else if ( signingKey == null || signingPassphrase == null ) {
159
158
tasks. withType( Sign ). each { t -> t. enabled = false }
160
159
}
161
160
}
@@ -171,22 +170,18 @@ static String resolveSigningKey() {
171
170
return new File ( keyFile ). text
172
171
}
173
172
174
- throw new RuntimeException ( " Cannot perform signing without GPG details. " )
173
+ return null
175
174
}
176
175
177
176
static String resolveSigningPassphrase () {
178
- var passphrase = System . getenv(). get( " SIGNING_GPG_PASSPHRASE" )
179
- if ( passphrase == null ) {
180
- throw new RuntimeException ( " Cannot perform signing without GPG details." )
181
- }
182
- return passphrase
177
+ return System . getenv(). get( " SIGNING_GPG_PASSPHRASE" )
183
178
}
184
179
185
180
186
181
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
187
182
// Release / publishing tasks
188
183
189
- task ciBuild {
184
+ tasks . register( ' ciBuild' ) {
190
185
dependsOn test, tasks. publishToSonatype
191
186
}
192
187
@@ -200,16 +195,17 @@ tasks.preVerifyRelease.dependsOn generatePomFileForRelocationPomPublication
200
195
tasks. publishToSonatype. mustRunAfter test
201
196
202
197
198
+
203
199
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
204
200
// Ancillary tasks
205
201
206
- task showPublications {
202
+ tasks . register( ' showPublications' ) {
207
203
doFirst {
208
- project . publishing. publications. each { publication ->
204
+ publishing. publications. each { publication ->
209
205
println " Publication (${ publication.name} ): ${ publication.groupId} :${ publication.artifactId} :${ publication.version} "
210
206
publication. artifacts. each { artifact ->
211
207
println " > ${ artifact} "
212
208
}
213
209
}
214
210
}
215
- }
211
+ }
0 commit comments