From e42354876cdb13fa27f21359dd170665010f489b Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Thu, 21 Aug 2025 12:16:02 -0400 Subject: [PATCH 01/10] Enable warnings as errors --- .../kotlin/gradle/codegen/GenerateSmithyBuildTaskTest.kt | 8 ++++---- build.gradle.kts | 7 +++++++ .../software/aws/ktlint/rules/CopyrightHeaderRule.kt | 1 + .../software/aws/ktlint/rules/ExpressionBodyRule.kt | 1 + .../software/aws/ktlint/rules/MultilineIfElseBlockRule.kt | 1 + 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/build-plugins/smithy-build/src/test/kotlin/aws/sdk/kotlin/gradle/codegen/GenerateSmithyBuildTaskTest.kt b/build-plugins/smithy-build/src/test/kotlin/aws/sdk/kotlin/gradle/codegen/GenerateSmithyBuildTaskTest.kt index 1a34b3a6..569bdcf8 100644 --- a/build-plugins/smithy-build/src/test/kotlin/aws/sdk/kotlin/gradle/codegen/GenerateSmithyBuildTaskTest.kt +++ b/build-plugins/smithy-build/src/test/kotlin/aws/sdk/kotlin/gradle/codegen/GenerateSmithyBuildTaskTest.kt @@ -8,7 +8,7 @@ import aws.sdk.kotlin.gradle.codegen.dsl.SmithyBuildPluginSettings import aws.sdk.kotlin.gradle.codegen.dsl.SmithyProjection import aws.sdk.kotlin.gradle.codegen.tasks.GenerateSmithyBuild import aws.sdk.kotlin.gradle.codegen.tasks.json -import org.gradle.kotlin.dsl.create +import org.gradle.kotlin.dsl.register import org.gradle.testfixtures.ProjectBuilder import software.amazon.smithy.model.node.Node import kotlin.test.Test @@ -19,7 +19,7 @@ class GenerateSmithyBuildTaskTest { @Test fun testDefaults() { val testProj = ProjectBuilder.builder().build() - val task = testProj.tasks.create("generateSmithyBuild") + val task = testProj.tasks.register("generateSmithyBuild").get() assertEquals(task.generatedOutput.get().asFile.path, testProj.layout.buildDirectory.file("smithy-build.json").get().asFile.path) } @@ -42,9 +42,9 @@ class GenerateSmithyBuildTaskTest { plugins["plugin1"] = testPlugin }, ) - val task = testProj.tasks.create("generateSmithyBuild") { + val task = testProj.tasks.register("generateSmithyBuild") { smithyBuildConfig.set(smithyProjections.json) - } + }.get() task.generateSmithyBuild() assertTrue(task.generatedOutput.get().asFile.exists()) diff --git a/build.gradle.kts b/build.gradle.kts index c2810059..48f6dc9a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,6 +2,8 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + plugins { `maven-publish` alias(libs.plugins.kotlin.jvm) apply false @@ -16,6 +18,11 @@ if (s3Url == null) logger.warn("S3 repository not configured, missing S3 url") allprojects { // Enables running `./gradlew allDeps` to get a comprehensive list of dependencies for every subproject tasks.register("allDeps") { } + tasks.withType { + compilerOptions { + allWarningsAsErrors = true + } + } } subprojects { diff --git a/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/CopyrightHeaderRule.kt b/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/CopyrightHeaderRule.kt index dc0d9f1b..d82a2d3c 100644 --- a/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/CopyrightHeaderRule.kt +++ b/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/CopyrightHeaderRule.kt @@ -22,6 +22,7 @@ class CopyrightHeaderRule : Rule(RuleId("copyright-header"), About()) { """.trimIndent() } + @Deprecated("Marked for removal in Ktlint 2.0. Please implement interface RuleAutocorrectApproveHandler.") override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, diff --git a/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/ExpressionBodyRule.kt b/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/ExpressionBodyRule.kt index e54e5c0e..bc3f7216 100644 --- a/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/ExpressionBodyRule.kt +++ b/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/ExpressionBodyRule.kt @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.psi.KtNamedFunction import org.jetbrains.kotlin.psi.KtReturnExpression class ExpressionBodyRule : Rule(RuleId("expression-body"), About()) { + @Deprecated("Marked for removal in Ktlint 2.0. Please implement interface RuleAutocorrectApproveHandler.") override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, diff --git a/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/MultilineIfElseBlockRule.kt b/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/MultilineIfElseBlockRule.kt index 16fc2e8d..a54aa466 100644 --- a/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/MultilineIfElseBlockRule.kt +++ b/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/MultilineIfElseBlockRule.kt @@ -10,6 +10,7 @@ import com.pinterest.ktlint.rule.engine.core.api.RuleId import org.jetbrains.kotlin.com.intellij.lang.ASTNode class MultilineIfElseBlockRule : Rule(RuleId("multiline-if-else-block"), About()) { + @Deprecated("Marked for removal in Ktlint 2.0. Please implement interface RuleAutocorrectApproveHandler.") override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, From 79b5a61c0c8c9497362fecb5739d09f42368d18d Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Thu, 21 Aug 2025 12:55:49 -0400 Subject: [PATCH 02/10] Use group names for K/N validation, add iosSimulatorArm64, add override for local development --- .../aws/sdk/kotlin/gradle/dsl/Publish.kt | 28 +++++--- .../aws/sdk/kotlin/gradle/dsl/PublishTest.kt | 69 ++++++++++++++++++- 2 files changed, 84 insertions(+), 13 deletions(-) diff --git a/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt b/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt index 853240d1..3e268240 100644 --- a/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt +++ b/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt @@ -4,6 +4,7 @@ */ package aws.sdk.kotlin.gradle.dsl +import aws.sdk.kotlin.gradle.util.getOrNull import aws.sdk.kotlin.gradle.util.verifyRootProject import io.github.gradlenexus.publishplugin.NexusPublishExtension import org.gradle.api.Project @@ -56,9 +57,11 @@ internal val ALLOWED_PUBLICATION_NAMES = setOf( "dynamodb-mapper-schema-generatorPluginMarkerMaven", ) -internal val KOTLIN_NATIVE_PUBLICATION_NAMES = setOf( +internal val ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES = setOf( "iosArm64", + "iosSimulatorArm64", "iosX64", + "linuxArm64", "linuxX64", "macosArm64", @@ -66,12 +69,15 @@ internal val KOTLIN_NATIVE_PUBLICATION_NAMES = setOf( "mingwX64", ) -// TODO Refactor to support project names _or_ publication group names. -// aws-crt-kotlin is not published with a group name, so we need to check project names instead. -private val KOTLIN_NATIVE_PROJECT_NAMES = setOf( - "aws-crt-kotlin", +// Group names which are allowed to publish K/N artifacts +private val ALLOWED_KOTLIN_NATIVE_GROUP_NAMES = setOf( + "aws.sdk.kotlin.crt", ) +// Optional override to the above set. +// Used to support local development where you want to run publishToMavenLocal in smithy-kotlin, aws-sdk-kotlin. +internal const val OVERRIDE_KOTLIN_NATIVE_GROUP_NAME_VALIDATION = "aws.kotlin.native.overridePublication" + /** * Mark this project as excluded from publishing */ @@ -381,16 +387,18 @@ internal fun isAvailableForPublication(project: Project, publication: MavenPubli // Check SKIP_PUBLISH_PROP if (project.extra.has(Properties.SKIP_PUBLISHING)) shouldPublish = false - // Only publish publications with the configured group from JReleaser or everything if JReleaser group is not configured + // Only publish publications with the configured group from JReleaser, or everything if JReleaser group is not configured val publishGroupName = System.getenv(EnvironmentVariables.GROUP_ID) - shouldPublish = shouldPublish && (publishGroupName == null || publication.groupId.startsWith(publishGroupName)) + shouldPublish = shouldPublish && (publishGroupName == null || publication.groupId.equals(publishGroupName, ignoreCase = true)) + + val overrideGroupNameValidation = project.extra.getOrNull(OVERRIDE_KOTLIN_NATIVE_GROUP_NAME_VALIDATION) == "true" + if (overrideGroupNameValidation) println("Overriding group name validation for Kotlin/Native publications") // Validate publication name is allowed to be published shouldPublish = shouldPublish && ( - ALLOWED_PUBLICATION_NAMES.any { publication.name.equals(it, ignoreCase = true) } || - // standard publication - (KOTLIN_NATIVE_PUBLICATION_NAMES.any { publication.name.equals(it, ignoreCase = true) } && KOTLIN_NATIVE_PROJECT_NAMES.any { project.name.equals(it, ignoreCase = true) }) // Kotlin/Native publication + ALLOWED_PUBLICATION_NAMES.any { publication.name.equals(it, ignoreCase = true) } || // standard publication + (ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES.any { publication.name.equals(it, ignoreCase = true) } && (overrideGroupNameValidation || ALLOWED_KOTLIN_NATIVE_GROUP_NAMES.any { publication.groupId.equals(it, ignoreCase = true) })) // Kotlin/Native publication ) return shouldPublish diff --git a/build-plugins/build-support/src/test/kotlin/aws/sdk/kotlin/gradle/dsl/PublishTest.kt b/build-plugins/build-support/src/test/kotlin/aws/sdk/kotlin/gradle/dsl/PublishTest.kt index 45d7c7d4..65dd4688 100644 --- a/build-plugins/build-support/src/test/kotlin/aws/sdk/kotlin/gradle/dsl/PublishTest.kt +++ b/build-plugins/build-support/src/test/kotlin/aws/sdk/kotlin/gradle/dsl/PublishTest.kt @@ -7,6 +7,7 @@ package aws.sdk.kotlin.gradle.dsl import kotlinx.coroutines.test.runTest import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.maven.MavenPublication +import org.gradle.internal.extensions.core.extra import org.gradle.testfixtures.ProjectBuilder import kotlin.test.Test import kotlin.test.assertFalse @@ -32,7 +33,7 @@ class PublishTest { assertTrue(isAvailableForPublication(project, jvmRuntimePublication)) } - KOTLIN_NATIVE_PUBLICATION_NAMES.forEach { + ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES.forEach { val nativeRuntimePublication = create(it, MavenPublication::class.java).apply { groupId = "aws.sdk.kotlin.crt" version = "1.2.3" @@ -62,7 +63,7 @@ class PublishTest { assertTrue(isAvailableForPublication(project, jvmRuntimePublication)) } - KOTLIN_NATIVE_PUBLICATION_NAMES.forEach { + ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES.forEach { val nativeRuntimePublication = create(it, MavenPublication::class.java).apply { groupId = "aws.sdk.kotlin" version = "1.2.3" @@ -92,7 +93,69 @@ class PublishTest { assertTrue(isAvailableForPublication(project, jvmRuntimePublication)) } - KOTLIN_NATIVE_PUBLICATION_NAMES.forEach { + ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES.forEach { + val nativeRuntimePublication = create(it, MavenPublication::class.java).apply { + groupId = "aws.smithy.kotlin" + version = "1.2.3" + artifactId = "runtime" + } + assertFalse(isAvailableForPublication(project, nativeRuntimePublication)) + } + } + } + + @Test + fun `users can override smithy-kotlin publication`() = runTest { + val project = ProjectBuilder.builder().withName("aws-smithy-kotlin").build() + project.group = "aws.smithy.kotlin" + project.version = "1.2.3" + project.extra.set(OVERRIDE_KOTLIN_NATIVE_GROUP_NAME_VALIDATION, "true") + + project.configurePublishing("smithy-kotlin", "smithy-lang") + + val publishing = project.extensions.getByType(PublishingExtension::class.java) + publishing.publications { + ALLOWED_PUBLICATION_NAMES.forEach { + val jvmRuntimePublication = create(it, MavenPublication::class.java).apply { + groupId = "aws.smithy.kotlin" + version = "1.2.3" + artifactId = "runtime" + } + assertTrue(isAvailableForPublication(project, jvmRuntimePublication)) + } + + ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES.forEach { + val nativeRuntimePublication = create(it, MavenPublication::class.java).apply { + groupId = "aws.smithy.kotlin" + version = "1.2.3" + artifactId = "runtime" + } + assertTrue(isAvailableForPublication(project, nativeRuntimePublication)) + } + } + } + + @Test + fun `override only works when set to true`() = runTest { + val project = ProjectBuilder.builder().withName("aws-smithy-kotlin").build() + project.group = "aws.smithy.kotlin" + project.version = "1.2.3" + project.extra.set(OVERRIDE_KOTLIN_NATIVE_GROUP_NAME_VALIDATION, "this is not true") + + project.configurePublishing("smithy-kotlin", "smithy-lang") + + val publishing = project.extensions.getByType(PublishingExtension::class.java) + publishing.publications { + ALLOWED_PUBLICATION_NAMES.forEach { + val jvmRuntimePublication = create(it, MavenPublication::class.java).apply { + groupId = "aws.smithy.kotlin" + version = "1.2.3" + artifactId = "runtime" + } + assertTrue(isAvailableForPublication(project, jvmRuntimePublication)) + } + + ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES.forEach { val nativeRuntimePublication = create(it, MavenPublication::class.java).apply { groupId = "aws.smithy.kotlin" version = "1.2.3" From e347e3a75cd58461a5ba1c39994e732884ec2743 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Thu, 21 Aug 2025 12:58:23 -0400 Subject: [PATCH 03/10] Revert "Enable warnings as errors" This reverts commit e42354876cdb13fa27f21359dd170665010f489b. --- .../kotlin/gradle/codegen/GenerateSmithyBuildTaskTest.kt | 8 ++++---- build.gradle.kts | 7 ------- .../software/aws/ktlint/rules/CopyrightHeaderRule.kt | 1 - .../software/aws/ktlint/rules/ExpressionBodyRule.kt | 1 - .../software/aws/ktlint/rules/MultilineIfElseBlockRule.kt | 1 - 5 files changed, 4 insertions(+), 14 deletions(-) diff --git a/build-plugins/smithy-build/src/test/kotlin/aws/sdk/kotlin/gradle/codegen/GenerateSmithyBuildTaskTest.kt b/build-plugins/smithy-build/src/test/kotlin/aws/sdk/kotlin/gradle/codegen/GenerateSmithyBuildTaskTest.kt index 569bdcf8..1a34b3a6 100644 --- a/build-plugins/smithy-build/src/test/kotlin/aws/sdk/kotlin/gradle/codegen/GenerateSmithyBuildTaskTest.kt +++ b/build-plugins/smithy-build/src/test/kotlin/aws/sdk/kotlin/gradle/codegen/GenerateSmithyBuildTaskTest.kt @@ -8,7 +8,7 @@ import aws.sdk.kotlin.gradle.codegen.dsl.SmithyBuildPluginSettings import aws.sdk.kotlin.gradle.codegen.dsl.SmithyProjection import aws.sdk.kotlin.gradle.codegen.tasks.GenerateSmithyBuild import aws.sdk.kotlin.gradle.codegen.tasks.json -import org.gradle.kotlin.dsl.register +import org.gradle.kotlin.dsl.create import org.gradle.testfixtures.ProjectBuilder import software.amazon.smithy.model.node.Node import kotlin.test.Test @@ -19,7 +19,7 @@ class GenerateSmithyBuildTaskTest { @Test fun testDefaults() { val testProj = ProjectBuilder.builder().build() - val task = testProj.tasks.register("generateSmithyBuild").get() + val task = testProj.tasks.create("generateSmithyBuild") assertEquals(task.generatedOutput.get().asFile.path, testProj.layout.buildDirectory.file("smithy-build.json").get().asFile.path) } @@ -42,9 +42,9 @@ class GenerateSmithyBuildTaskTest { plugins["plugin1"] = testPlugin }, ) - val task = testProj.tasks.register("generateSmithyBuild") { + val task = testProj.tasks.create("generateSmithyBuild") { smithyBuildConfig.set(smithyProjections.json) - }.get() + } task.generateSmithyBuild() assertTrue(task.generatedOutput.get().asFile.exists()) diff --git a/build.gradle.kts b/build.gradle.kts index 48f6dc9a..c2810059 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,8 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { `maven-publish` alias(libs.plugins.kotlin.jvm) apply false @@ -18,11 +16,6 @@ if (s3Url == null) logger.warn("S3 repository not configured, missing S3 url") allprojects { // Enables running `./gradlew allDeps` to get a comprehensive list of dependencies for every subproject tasks.register("allDeps") { } - tasks.withType { - compilerOptions { - allWarningsAsErrors = true - } - } } subprojects { diff --git a/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/CopyrightHeaderRule.kt b/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/CopyrightHeaderRule.kt index d82a2d3c..dc0d9f1b 100644 --- a/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/CopyrightHeaderRule.kt +++ b/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/CopyrightHeaderRule.kt @@ -22,7 +22,6 @@ class CopyrightHeaderRule : Rule(RuleId("copyright-header"), About()) { """.trimIndent() } - @Deprecated("Marked for removal in Ktlint 2.0. Please implement interface RuleAutocorrectApproveHandler.") override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, diff --git a/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/ExpressionBodyRule.kt b/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/ExpressionBodyRule.kt index bc3f7216..e54e5c0e 100644 --- a/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/ExpressionBodyRule.kt +++ b/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/ExpressionBodyRule.kt @@ -12,7 +12,6 @@ import org.jetbrains.kotlin.psi.KtNamedFunction import org.jetbrains.kotlin.psi.KtReturnExpression class ExpressionBodyRule : Rule(RuleId("expression-body"), About()) { - @Deprecated("Marked for removal in Ktlint 2.0. Please implement interface RuleAutocorrectApproveHandler.") override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, diff --git a/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/MultilineIfElseBlockRule.kt b/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/MultilineIfElseBlockRule.kt index a54aa466..16fc2e8d 100644 --- a/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/MultilineIfElseBlockRule.kt +++ b/ktlint-rules/src/main/kotlin/software/aws/ktlint/rules/MultilineIfElseBlockRule.kt @@ -10,7 +10,6 @@ import com.pinterest.ktlint.rule.engine.core.api.RuleId import org.jetbrains.kotlin.com.intellij.lang.ASTNode class MultilineIfElseBlockRule : Rule(RuleId("multiline-if-else-block"), About()) { - @Deprecated("Marked for removal in Ktlint 2.0. Please implement interface RuleAutocorrectApproveHandler.") override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, From 8ed94791a0c7dd3937eddbdb6a5e41c204a733f5 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Thu, 21 Aug 2025 13:02:29 -0400 Subject: [PATCH 04/10] ktlint --- .../src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt b/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt index 3e268240..dcbd8f55 100644 --- a/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt +++ b/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt @@ -397,7 +397,8 @@ internal fun isAvailableForPublication(project: Project, publication: MavenPubli // Validate publication name is allowed to be published shouldPublish = shouldPublish && ( - ALLOWED_PUBLICATION_NAMES.any { publication.name.equals(it, ignoreCase = true) } || // standard publication + ALLOWED_PUBLICATION_NAMES.any { publication.name.equals(it, ignoreCase = true) } || + // standard publication (ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES.any { publication.name.equals(it, ignoreCase = true) } && (overrideGroupNameValidation || ALLOWED_KOTLIN_NATIVE_GROUP_NAMES.any { publication.groupId.equals(it, ignoreCase = true) })) // Kotlin/Native publication ) From 8c8a550386f75fe51e2189d4f20c979ab80a38d5 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Thu, 21 Aug 2025 13:04:52 -0400 Subject: [PATCH 05/10] Change property --- .../src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt b/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt index dcbd8f55..01178d30 100644 --- a/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt +++ b/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt @@ -76,7 +76,7 @@ private val ALLOWED_KOTLIN_NATIVE_GROUP_NAMES = setOf( // Optional override to the above set. // Used to support local development where you want to run publishToMavenLocal in smithy-kotlin, aws-sdk-kotlin. -internal const val OVERRIDE_KOTLIN_NATIVE_GROUP_NAME_VALIDATION = "aws.kotlin.native.overridePublication" +internal const val OVERRIDE_KOTLIN_NATIVE_GROUP_NAME_VALIDATION = "aws.kotlin.native.allowPublication" /** * Mark this project as excluded from publishing From 8dcf82c05c1c0eb52f1d80646209d141edaddeea Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 22 Aug 2025 13:37:34 -0400 Subject: [PATCH 06/10] Clean up JReleaser configuration --- .../aws/sdk/kotlin/gradle/dsl/Publish.kt | 58 +++++++++---------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt b/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt index 01178d30..0c500c97 100644 --- a/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt +++ b/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt @@ -37,6 +37,7 @@ private object EnvironmentVariables { const val GPG_PASSPHRASE = "JRELEASER_GPG_PASSPHRASE" const val GPG_PUBLIC_KEY = "JRELEASER_GPG_PUBLIC_KEY" const val GPG_SECRET_KEY = "JRELEASER_GPG_SECRET_KEY" + const val GENERIC_TOKEN = "JRELEASER_GENERIC_TOKEN" } internal val ALLOWED_PUBLICATION_NAMES = setOf( @@ -243,10 +244,7 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = " if (!secretKey.isNullOrBlank() && !passphrase.isNullOrBlank()) { apply(plugin = "signing") extensions.configure { - useInMemoryPgpKeys( - secretKey, - passphrase, - ) + useInMemoryPgpKeys(secretKey, passphrase) sign(publications) } @@ -312,20 +310,19 @@ fun Project.configureNexus( fun Project.configureJReleaser() { verifyRootProject { "JReleaser configuration must be applied to the root project only" } - var missingVariables = false - listOf( + val requiredVariables = listOf( EnvironmentVariables.MAVEN_CENTRAL_USERNAME, EnvironmentVariables.MAVEN_CENTRAL_TOKEN, EnvironmentVariables.GPG_PASSPHRASE, EnvironmentVariables.GPG_PUBLIC_KEY, EnvironmentVariables.GPG_SECRET_KEY, - ).forEach { - if (System.getenv(it).isNullOrBlank()) { - missingVariables = true - logger.info("Skipping JReleaser configuration, missing required environment variable: $it") - } + EnvironmentVariables.GENERIC_TOKEN, + ) + + if (!requiredVariables.all { System.getenv(it).isNotBlank() }) { + println("Skipping JReleaser configuration, missing one or more required environment variables: ${requiredVariables.joinToString()}") + return } - if (missingVariables) return // Get SDK version from gradle.properties val sdkVersion: String by project @@ -336,23 +333,22 @@ fun Project.configureJReleaser() { version = sdkVersion } + // FIXME We're currently signing the artifacts twice. Once using the logic in configurePublishing above, + // and the second time during JReleaser's signing stage. signing { active = Active.ALWAYS armored = true } - // Used for creating a tagged release, uploading files and generating changelogs. - // In the future we can set this up to push release tags to GitHub, but for now it's - // set up to do nothing. - // https://jreleaser.org/guide/latest/reference/release/index.html + // JReleaser requires a releaser to be configured even though we don't use it. + // https://github.com/jreleaser/jreleaser/discussions/1725#discussioncomment-10674529 release { generic { - enabled = true skipRelease = true } } - // Used to announce a release to configured announcers. + // We don't announce our releases anywhere // https://jreleaser.org/guide/latest/reference/announce/index.html announce { active = Active.NEVER @@ -362,14 +358,13 @@ fun Project.configureJReleaser() { maven { mavenCentral { create("maven-central") { - active = Active.ALWAYS url = "https://central.sonatype.com/api/v1/publisher" stagingRepository(rootProject.layout.buildDirectory.dir("m2").get().toString()) artifacts { artifactOverride { artifactId = "version-catalog" - jar = false - verifyPom = false // jreleaser doesn't understand toml packaging + jar = false // Version catalogs don't produce a JAR + verifyPom = false // JReleaser fails when processing toml tags: `Unknown packaging: toml` } } maxRetries = 100 @@ -387,20 +382,19 @@ internal fun isAvailableForPublication(project: Project, publication: MavenPubli // Check SKIP_PUBLISH_PROP if (project.extra.has(Properties.SKIP_PUBLISHING)) shouldPublish = false - // Only publish publications with the configured group from JReleaser, or everything if JReleaser group is not configured - val publishGroupName = System.getenv(EnvironmentVariables.GROUP_ID) - shouldPublish = shouldPublish && (publishGroupName == null || publication.groupId.equals(publishGroupName, ignoreCase = true)) - + // Allow overriding K/N publications for local development val overrideGroupNameValidation = project.extra.getOrNull(OVERRIDE_KOTLIN_NATIVE_GROUP_NAME_VALIDATION) == "true" if (overrideGroupNameValidation) println("Overriding group name validation for Kotlin/Native publications") - // Validate publication name is allowed to be published - shouldPublish = shouldPublish && - ( - ALLOWED_PUBLICATION_NAMES.any { publication.name.equals(it, ignoreCase = true) } || - // standard publication - (ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES.any { publication.name.equals(it, ignoreCase = true) } && (overrideGroupNameValidation || ALLOWED_KOTLIN_NATIVE_GROUP_NAMES.any { publication.groupId.equals(it, ignoreCase = true) })) // Kotlin/Native publication - ) + // Validate publication name + if (publication.name in ALLOWED_PUBLICATION_NAMES) { + // Standard publication + } else if (publication.name in ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES) { + // Kotlin/Native publication + shouldPublish = shouldPublish && (overrideGroupNameValidation || publication.groupId in ALLOWED_KOTLIN_NATIVE_GROUP_NAMES) + } else { + shouldPublish = false + } return shouldPublish } From 6acc807920a1f95c91d7f0b14d9d84e0f370a286 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 22 Aug 2025 13:42:00 -0400 Subject: [PATCH 07/10] Refine log message --- .../src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt b/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt index 0c500c97..7db52540 100644 --- a/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt +++ b/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt @@ -384,14 +384,17 @@ internal fun isAvailableForPublication(project: Project, publication: MavenPubli // Allow overriding K/N publications for local development val overrideGroupNameValidation = project.extra.getOrNull(OVERRIDE_KOTLIN_NATIVE_GROUP_NAME_VALIDATION) == "true" - if (overrideGroupNameValidation) println("Overriding group name validation for Kotlin/Native publications") // Validate publication name if (publication.name in ALLOWED_PUBLICATION_NAMES) { // Standard publication } else if (publication.name in ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES) { // Kotlin/Native publication - shouldPublish = shouldPublish && (overrideGroupNameValidation || publication.groupId in ALLOWED_KOTLIN_NATIVE_GROUP_NAMES) + if (overrideGroupNameValidation && publication.groupId !in ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES) { + println("Overriding K/N publication, project=${project.name}; publication=${publication.name}; group=${publication.groupId}") + } else { + shouldPublish = shouldPublish && publication.groupId in ALLOWED_KOTLIN_NATIVE_GROUP_NAMES + } } else { shouldPublish = false } From 9393e4f42abc8e10f246356ea360afa12da84bc2 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 22 Aug 2025 15:08:05 -0400 Subject: [PATCH 08/10] Use logger --- .../aws/sdk/kotlin/gradle/dsl/Publish.kt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt b/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt index 7db52540..0ebf338c 100644 --- a/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt +++ b/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt @@ -320,7 +320,7 @@ fun Project.configureJReleaser() { ) if (!requiredVariables.all { System.getenv(it).isNotBlank() }) { - println("Skipping JReleaser configuration, missing one or more required environment variables: ${requiredVariables.joinToString()}") + logger.info("Skipping JReleaser configuration, missing one or more required environment variables: ${requiredVariables.joinToString()}") return } @@ -361,6 +361,7 @@ fun Project.configureJReleaser() { url = "https://central.sonatype.com/api/v1/publisher" stagingRepository(rootProject.layout.buildDirectory.dir("m2").get().toString()) artifacts { + verifyPom = false // Sonatype already verifies POMs, and JReleaser's validator is not compatible with TOML or klib types. artifactOverride { artifactId = "version-catalog" jar = false // Version catalogs don't produce a JAR @@ -376,6 +377,21 @@ fun Project.configureJReleaser() { } } +internal fun Project.configureJReleaserKotlinNativeOverrides() { + val nativePublications = tasks.withType().filter { + it.publication.name in ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES + } + extensions.configure { + deploy { + maven { + mavenCentral { + + } + } + } + } +} + internal fun isAvailableForPublication(project: Project, publication: MavenPublication): Boolean { var shouldPublish = true From ff88c9c5948e4d00dec968dea2b0f2b76b1d52cb Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 22 Aug 2025 17:18:32 -0400 Subject: [PATCH 09/10] Disable verification of klib artifacts --- .../aws/sdk/kotlin/gradle/dsl/Publish.kt | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt b/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt index 0ebf338c..722f03cc 100644 --- a/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt +++ b/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt @@ -319,18 +319,27 @@ fun Project.configureJReleaser() { EnvironmentVariables.GENERIC_TOKEN, ) - if (!requiredVariables.all { System.getenv(it).isNotBlank() }) { - logger.info("Skipping JReleaser configuration, missing one or more required environment variables: ${requiredVariables.joinToString()}") + if (!requiredVariables.all { !System.getenv(it).isNullOrBlank() }) { + logger.warn("Skipping JReleaser configuration, missing one or more required environment variables: ${requiredVariables.joinToString()}") return } - // Get SDK version from gradle.properties - val sdkVersion: String by project + // Collect a set of native artifact IDs from every project + val nativeArtifactIds = providers.provider { + allprojects.flatMap { + it.extensions.findByType(PublishingExtension::class.java) + ?.publications + ?.withType(MavenPublication::class.java) + ?.filter { it.name in ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES } + ?.map { it.artifactId } + ?: emptySet() + }.toSet() + } apply(plugin = "org.jreleaser") extensions.configure { project { - version = sdkVersion + version = providers.gradleProperty("sdkVersion").get() } // FIXME We're currently signing the artifacts twice. Once using the logic in configurePublishing above, @@ -365,7 +374,17 @@ fun Project.configureJReleaser() { artifactOverride { artifactId = "version-catalog" jar = false // Version catalogs don't produce a JAR - verifyPom = false // JReleaser fails when processing toml tags: `Unknown packaging: toml` + verifyPom = false // JReleaser fails when processing toml tag: `Unknown packaging: toml` + } + gradle.projectsEvaluated { + nativeArtifactIds.get().forEach { + artifactOverride { + artifactId = it + jar = false // Native artifacts produce klibs, not JARs + verifyPom = false // JReleaser fails when processing klib tag: `Unknown packaging: klib` + } + } + logger.info("Configured JReleaser artifact overrides for the following artifacts: ${nativeArtifactIds.get().joinToString()}") } } maxRetries = 100 @@ -377,21 +396,6 @@ fun Project.configureJReleaser() { } } -internal fun Project.configureJReleaserKotlinNativeOverrides() { - val nativePublications = tasks.withType().filter { - it.publication.name in ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES - } - extensions.configure { - deploy { - maven { - mavenCentral { - - } - } - } - } -} - internal fun isAvailableForPublication(project: Project, publication: MavenPublication): Boolean { var shouldPublish = true From 79d0f1754f6677aecd2aebb61fef56bf9cc034ed Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 22 Aug 2025 17:19:31 -0400 Subject: [PATCH 10/10] Re-enable verifyPom for most artifacts --- .../src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt b/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt index 722f03cc..96f85c58 100644 --- a/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt +++ b/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt @@ -370,7 +370,6 @@ fun Project.configureJReleaser() { url = "https://central.sonatype.com/api/v1/publisher" stagingRepository(rootProject.layout.buildDirectory.dir("m2").get().toString()) artifacts { - verifyPom = false // Sonatype already verifies POMs, and JReleaser's validator is not compatible with TOML or klib types. artifactOverride { artifactId = "version-catalog" jar = false // Version catalogs don't produce a JAR