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