@@ -182,7 +182,8 @@ fun Project.configureNexusPublishing(repoName: String, githubOrganization: Strin
182182}
183183
184184/* *
185- * Configure publishing for this project. This applies the `maven-publish` plugin and configures publications.
185+ * Configure publishing for this project. This applies the `maven-publish` and `signing` plugins and configures
186+ * the publications.
186187 * @param repoName the repository name (e.g. `smithy-kotlin`, `aws-sdk-kotlin`, etc)
187188 * @param githubOrganization the name of the GitHub organization that [repoName] is located in
188189 */
@@ -235,6 +236,23 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = "
235236 }
236237 }
237238 }
239+
240+ val secretKey = System .getenv(EnvironmentVariables .GPG_SECRET_KEY )
241+ val passphrase = System .getenv(EnvironmentVariables .GPG_PASSPHRASE )
242+
243+ if (! secretKey.isNullOrBlank() && ! passphrase.isNullOrBlank()) {
244+ apply (plugin = " signing" )
245+ extensions.configure<SigningExtension > {
246+ useInMemoryPgpKeys(secretKey, passphrase)
247+ sign(publications)
248+ }
249+
250+ // FIXME - workaround for https://github.com/gradle/gradle/issues/26091
251+ val signingTasks = tasks.withType<Sign >()
252+ tasks.withType<AbstractPublishToMaven >().configureEach {
253+ mustRunAfter(signingTasks)
254+ }
255+ }
238256 }
239257
240258 tasks.withType<AbstractPublishToMaven >().configureEach {
@@ -294,9 +312,6 @@ fun Project.configureJReleaser() {
294312 val requiredVariables = listOf (
295313 EnvironmentVariables .MAVEN_CENTRAL_USERNAME ,
296314 EnvironmentVariables .MAVEN_CENTRAL_TOKEN ,
297- EnvironmentVariables .GPG_PASSPHRASE ,
298- EnvironmentVariables .GPG_PUBLIC_KEY ,
299- EnvironmentVariables .GPG_SECRET_KEY ,
300315 EnvironmentVariables .GENERIC_TOKEN ,
301316 )
302317
@@ -331,11 +346,6 @@ fun Project.configureJReleaser() {
331346 version = providers.gradleProperty(" sdkVersion" ).get()
332347 }
333348
334- signing {
335- active = Active .ALWAYS
336- armored = true
337- }
338-
339349 // JReleaser requires a releaser to be configured even though we don't use it.
340350 // https://github.com/jreleaser/jreleaser/discussions/1725#discussioncomment-10674529
341351 release {
@@ -355,6 +365,7 @@ fun Project.configureJReleaser() {
355365 mavenCentral {
356366 create(" maven-central" ) {
357367 active = Active .ALWAYS // the Maven deployer default is ALWAYS, but MavenCentral is NEVER
368+ sign = false // Signing is done when publishing, see the 'configurePublishing' function
358369 url = " https://central.sonatype.com/api/v1/publisher"
359370 stagingRepository(rootProject.layout.buildDirectory.dir(" m2" ).get().toString())
360371 artifacts {
0 commit comments