@@ -108,34 +108,18 @@ publishing {
108108// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
109109// Signing
110110
111- def signPublicationsTask = tasks. register(' signPublications' ) {
112- description " Grouping task which executes all Sign tasks"
113-
114- dependsOn tasks. withType( Sign )
115- }
116-
117- tasks. named( " publishPublishedArtifactsPublicationToSonatypeRepository" ) {
118- // publishing depends on signing
119- dependsOn signPublicationsTask
120- }
121-
122- tasks. register(' sign' ) {
123- description " Pseudonym for :signPublications"
124- dependsOn signPublicationsTask
125- }
111+ def signingKey = resolveSigningKey()
112+ def signingPassphrase = resolveSigningPassphrase()
126113
127114var signingExtension = project. getExtensions(). getByType(SigningExtension ) as SigningExtension
128- signingExtension. sign publishing. publications. publishedArtifacts
115+ signingExtension. sign publishingExtension. publications. publishedArtifacts
116+ signingExtension. useInMemoryPgpKeys(signingKey, signingPassphrase)
129117
130118gradle. taskGraph. whenReady { TaskExecutionGraph graph ->
131- boolean wasSigningRequested = false
132119 boolean wasPublishingRequested = false
133120
134121 graph. allTasks. each {task ->
135- if ( task instanceof Sign ) {
136- wasSigningRequested = true
137- }
138- else if ( task instanceof PublishToMavenRepository ) {
122+ if ( task instanceof PublishToMavenRepository ) {
139123 wasPublishingRequested = true
140124 }
141125 }
@@ -147,20 +131,9 @@ gradle.taskGraph.whenReady { TaskExecutionGraph graph ->
147131 throw new RuntimeException ( " Cannot perform publishing to OSSRH without credentials." )
148132 }
149133 logger. lifecycle " Publishing {} : {} : {}" , project. group, project. name, project. version
150- }
151-
152- if ( wasSigningRequested || wasPublishingRequested ) {
153- // signing was explicitly requested and/or we are publishing to Sonatype OSSRH
154- // - we need the signing to happen
155134 signingExtension. required = true
156-
157- var signingKey = resolveSigningKey()
158- var signingPassword = resolveSigningPassphrase()
159- signingExtension. useInMemoryPgpKeys( signingKey, signingPassword )
160135 }
161- else {
162- // signing was not explicitly requested and we are not publishing to OSSRH,
163- // - disable all Sign tasks
136+ else if ( signingKey == null || signingPassphrase == null ) {
164137 tasks. withType( Sign ). each { t -> t. enabled = false }
165138 }
166139}
@@ -176,15 +149,11 @@ static String resolveSigningKey() {
176149 return new File ( keyFile ). text
177150 }
178151
179- throw new RuntimeException ( " Cannot perform signing without GPG details. " )
152+ return null
180153}
181154
182155static String resolveSigningPassphrase () {
183- var passphrase = System . getenv(). get( " SIGNING_GPG_PASSPHRASE" )
184- if ( passphrase == null ) {
185- throw new RuntimeException ( " Cannot perform signing without GPG details." )
186- }
187- return passphrase
156+ return System . getenv(). get( " SIGNING_GPG_PASSPHRASE" )
188157}
189158
190159
0 commit comments