@@ -123,39 +123,35 @@ var signingExtension = project.getExtensions().getByType(SigningExtension) as Si
123123signingExtension. sign publishing. publications. publishedArtifacts
124124
125125gradle. taskGraph. whenReady { TaskExecutionGraph graph ->
126- boolean wasSigningRequested = false
127126 boolean wasPublishingRequested = false
128127
129128 graph. allTasks. each {task ->
130- if ( task instanceof Sign ) {
131- wasSigningRequested = true
132- }
133- else if ( task instanceof PublishToMavenRepository ) {
129+ if ( task instanceof PublishToMavenRepository ) {
134130 wasPublishingRequested = true
135131 }
136132 }
137133
134+ var signingKey = resolveSigningKey()
135+ var signingPassword = resolveSigningPassphrase()
136+
138137 if ( wasPublishingRequested ) {
138+ if ( signingKey == null || signingPassword == null ) {
139+ throw new RuntimeException (" Cannot perform signing without GPG details." )
140+ }
141+
139142 def ossrhUser = System . getenv(). get( " ORG_GRADLE_PROJECT_sonatypeUsername" )
140143 def ossrhPass = System . getenv(). get( " ORG_GRADLE_PROJECT_sonatypePassword" )
141144 if ( ossrhUser == null || ossrhPass == null ) {
142145 throw new RuntimeException ( " Cannot perform publishing to OSSRH without credentials." )
143146 }
144147 logger. lifecycle " Publishing {} : {} : {}" , project. group, project. name, project. version
145- }
146148
147- if ( wasSigningRequested || wasPublishingRequested ) {
148149 // signing was explicitly requested and/or we are publishing to Sonatype OSSRH
149150 // - we need the signing to happen
150151 signingExtension. required = true
151-
152- var signingKey = resolveSigningKey()
153- var signingPassword = resolveSigningPassphrase()
154152 signingExtension. useInMemoryPgpKeys( signingKey, signingPassword )
155153 }
156- else {
157- // signing was not explicitly requested and we are not publishing to OSSRH,
158- // - disable all Sign tasks
154+ else if ( signingKey == null || signingPassword == null ) {
159155 tasks. withType( Sign ). each { t -> t. enabled = false }
160156 }
161157}
@@ -171,15 +167,11 @@ static String resolveSigningKey() {
171167 return new File ( keyFile ). text
172168 }
173169
174- throw new RuntimeException ( " Cannot perform signing without GPG details. " )
170+ return null
175171}
176172
177173static 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
174+ return System . getenv(). get( " SIGNING_GPG_PASSPHRASE" )
183175}
184176
185177
0 commit comments