@@ -99,39 +99,49 @@ publishing {
9999 }
100100}
101101
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+ }
110111}
111112
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+ }
115122}
116123
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()
121130
122131var signingExtension = project. getExtensions(). getByType(SigningExtension ) as SigningExtension
123132signingExtension. sign publishing. publications. publishedArtifacts
133+ signingExtension. useInMemoryPgpKeys(signingKey, signingPassphrase)
134+
124135
125136gradle. taskGraph. whenReady { TaskExecutionGraph graph ->
126- boolean wasSigningRequested = false
137+ // are we publishing to OSSRH?
127138 boolean wasPublishingRequested = false
128139
129140 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+ }
135145 }
136146 }
137147
@@ -142,20 +152,9 @@ gradle.taskGraph.whenReady { TaskExecutionGraph graph ->
142152 throw new RuntimeException ( " Cannot perform publishing to OSSRH without credentials." )
143153 }
144154 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
150155 signingExtension. required = true
151-
152- var signingKey = resolveSigningKey()
153- var signingPassword = resolveSigningPassphrase()
154- signingExtension. useInMemoryPgpKeys( signingKey, signingPassword )
155156 }
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 ) {
159158 tasks. withType( Sign ). each { t -> t. enabled = false }
160159 }
161160}
@@ -171,22 +170,18 @@ static String resolveSigningKey() {
171170 return new File ( keyFile ). text
172171 }
173172
174- throw new RuntimeException ( " Cannot perform signing without GPG details. " )
173+ return null
175174}
176175
177176static 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" )
183178}
184179
185180
186181// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
187182// Release / publishing tasks
188183
189- task ciBuild {
184+ tasks . register( ' ciBuild' ) {
190185 dependsOn test, tasks. publishToSonatype
191186}
192187
@@ -200,16 +195,17 @@ tasks.preVerifyRelease.dependsOn generatePomFileForRelocationPomPublication
200195tasks. publishToSonatype. mustRunAfter test
201196
202197
198+
203199// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
204200// Ancillary tasks
205201
206- task showPublications {
202+ tasks . register( ' showPublications' ) {
207203 doFirst {
208- project . publishing. publications. each { publication ->
204+ publishing. publications. each { publication ->
209205 println " Publication (${ publication.name} ): ${ publication.groupId} :${ publication.artifactId} :${ publication.version} "
210206 publication. artifacts. each { artifact ->
211207 println " > ${ artifact} "
212208 }
213209 }
214210 }
215- }
211+ }
0 commit comments