From 2d41f847f2d4d9e0dcb6992c1c595805a2b90588 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Tue, 24 Jun 2025 14:29:41 -0400 Subject: [PATCH 01/10] feat: migrate from publish-plugin to jreleaser --- build-plugins/build-support/build.gradle.kts | 1 + .../aws/sdk/kotlin/gradle/dsl/Publish.kt | 76 +++++++++++-------- .../ArtifactSizeMetricsPlugin.kt | 2 +- gradle/libs.versions.toml | 1 + 4 files changed, 48 insertions(+), 32 deletions(-) diff --git a/build-plugins/build-support/build.gradle.kts b/build-plugins/build-support/build.gradle.kts index 6b981b87..4cf7b4ef 100644 --- a/build-plugins/build-support/build.gradle.kts +++ b/build-plugins/build-support/build.gradle.kts @@ -25,6 +25,7 @@ dependencies { } implementation(libs.nexusPublishPlugin) + implementation(libs.jReleaserPlugin) compileOnly(gradleApi()) implementation("aws.sdk.kotlin:s3:1.1.+") implementation("aws.sdk.kotlin:cloudwatch:1.1.+") 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 76b7958a..999bf948 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 @@ -5,7 +5,7 @@ package aws.sdk.kotlin.gradle.dsl import aws.sdk.kotlin.gradle.util.verifyRootProject -import io.github.gradlenexus.publishplugin.NexusPublishExtension +import org.jreleaser.gradle.plugin.JReleaserExtension import org.gradle.api.Project import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.maven.MavenPublication @@ -14,14 +14,19 @@ import org.gradle.api.tasks.bundling.Jar import org.gradle.kotlin.dsl.* import org.gradle.plugins.signing.Sign import org.gradle.plugins.signing.SigningExtension -import java.time.Duration +import org.jreleaser.model.Active private const val PUBLISH_GROUP_NAME_PROP = "publishGroupName" private const val SKIP_PUBLISH_PROP = "skipPublish" private const val SIGNING_KEY_PROP = "signingKey" private const val SIGNING_PASSWORD_PROP = "signingPassword" -private const val SONATYPE_USERNAME_PROP = "sonatypeUsername" -private const val SONATYPE_PASSWORD_PROP = "sonatypePassword" + +private const val J_RELEASER_MAVEN_CENTRAL_USERNAME_ENV_VAR = "JRELEASER_MAVENCENTRAL_USERNAME" +private const val J_RELEASER_MAVEN_CENTRAL_TOKEN_ENV_VAR = "JRELEASER_MAVENCENTRAL_TOKEN" +private const val J_RELEASER_GPG_PUBLIC_KEY_ENV_VAR = "JRELEASER_GPG_PUBLIC_KEY" +private const val J_RELEASER_GPG_SECRET_KEY_ENV_VAR = "JRELEASER_GPG_SECRET_KEY" +private const val J_RELEASER_GPG_PASSPHRASE_ENV_VAR = "JRELEASER_GPG_PASSPHRASE" +private const val J_RELEASER_ENV_VAR = "JRELEASER_PROJECT_JAVA_GROUP_ID" // Names of publications that are allowed to be published private val ALLOWED_PUBLICATIONS = listOf( @@ -56,7 +61,7 @@ fun Project.skipPublishing() { * @param repoName the repository name (e.g. `smithy-kotlin`, `aws-sdk-kotlin`, etc) * @param githubOrganization the name of the GitHub organization that [repoName] is located in */ -fun Project.configurePublishing(repoName: String, githubOrganization: String = "awslabs") { +fun Project.configurePublishing(repoName: String, githubOrganization: String = "awslabs") { // TODO: USE ENV VARS NOW ? val project = this apply(plugin = "maven-publish") @@ -136,35 +141,44 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = " } /** - * Configure nexus publishing plugin. This (conditionally) enables the `gradle-nexus.publish-plugin` and configures it. + * Configure JReleaser publishing plugin. This (conditionally) enables the `org.jreleaser` plugin and configures it. */ -fun Project.configureNexus() { - verifyRootProject { "Kotlin SDK nexus configuration must be applied to the root project only" } - - val requiredProps = listOf(SONATYPE_USERNAME_PROP, SONATYPE_PASSWORD_PROP, PUBLISH_GROUP_NAME_PROP) - val doConfigure = requiredProps.all { project.hasProperty(it) } - if (!doConfigure) { - logger.info("skipping nexus configuration, missing one or more required properties: $requiredProps") - return - } - - apply(plugin = "io.github.gradle-nexus.publish-plugin") - extensions.configure { - val publishGroupName = project.property(PUBLISH_GROUP_NAME_PROP) as String - group = publishGroupName - packageGroup.set(publishGroupName) - repositories { - create("awsNexus") { - nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/")) - snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/")) - username.set(project.property(SONATYPE_USERNAME_PROP) as String) - password.set(project.property(SONATYPE_PASSWORD_PROP) as String) - } +fun Project.configureJReleaser() { + verifyRootProject { "JReleaser configuration must be applied to the root project only" } + listOf( + J_RELEASER_MAVEN_CENTRAL_USERNAME_ENV_VAR, + J_RELEASER_MAVEN_CENTRAL_TOKEN_ENV_VAR, + J_RELEASER_GPG_PASSPHRASE_ENV_VAR, + J_RELEASER_GPG_SECRET_KEY_ENV_VAR, + J_RELEASER_GPG_PUBLIC_KEY_ENV_VAR, + J_RELEASER_ENV_VAR, + "JRELEASER_PROJECT_VERSION", // TODO: Keep ? + ).map { variable -> + if (System.getenv(variable) == null) { + logger.warn("Skipping JReleaser configuration, missing required env var: $variable") + true + } else { + false } + }.any { return } - transitionCheckOptions { - maxRetries.set(180) - delayBetween.set(Duration.ofSeconds(10)) + apply(plugin = "org.jreleaser") + extensions.configure { + signing { + active = Active.ALWAYS + armored = true + } + deploy { + maven { + mavenCentral { + create("maven-central") { + active = Active.ALWAYS + url = "https://central.sonatype.com/api/v1/publisher" // TODO: Use `gr jreleaserDeploy` +// sign = true // TODO: Remove me if unnecessary + stagingRepository("target/staging-deploy") + } + } + } } } } diff --git a/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/plugins/artifactsizemetrics/ArtifactSizeMetricsPlugin.kt b/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/plugins/artifactsizemetrics/ArtifactSizeMetricsPlugin.kt index b4ea5bf9..73c2651f 100644 --- a/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/plugins/artifactsizemetrics/ArtifactSizeMetricsPlugin.kt +++ b/build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/plugins/artifactsizemetrics/ArtifactSizeMetricsPlugin.kt @@ -31,7 +31,7 @@ class ArtifactSizeMetricsPlugin : Plugin { target.registerRootProjectArtifactSizeMetricsTask(tasks) - target.tasks.register("collectDelegatedArtifactSizeMetrics") { group = TASK_GROUP } +// target.tasks.register("collectDelegatedArtifactSizeMetrics") { group = TASK_GROUP } target.tasks.register("analyzeArtifactSizeMetrics") { group = TASK_GROUP } target.tasks.register("putArtifactSizeMetricsInCloudWatch") { group = TASK_GROUP } target.tasks.register("saveArtifactSizeMetrics") { group = TASK_GROUP } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index eb86ef9b..09f3b157 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,6 +10,7 @@ ktlint-rule-engine-core = { module = "com.pinterest.ktlint:ktlint-rule-engine-co ktlint-cli-ruleset-core = { module = "com.pinterest.ktlint:ktlint-cli-ruleset-core", version.ref = "ktlint" } ktlint-test = {module = "com.pinterest.ktlint:ktlint-test", version.ref = "ktlint" } nexusPublishPlugin = { module = "io.github.gradle-nexus:publish-plugin", version = "2.0.0" } +jReleaserPlugin = { module = "org.jreleaser:jreleaser-gradle-plugin", version = "1.18.0" } smithy-model = { module = "software.amazon.smithy:smithy-model", version.ref = "smithy-version" } smithy-gradle-base-plugin = { module = "software.amazon.smithy.gradle:smithy-base", version.ref = "smithy-gradle-plugin-version" } From 0c2c5f0f9f66d011694028489992a7a66e197331 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Tue, 1 Jul 2025 10:44:10 -0400 Subject: [PATCH 02/10] checkpoint --- .../aws/sdk/kotlin/gradle/dsl/Publish.kt | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 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 999bf948..8209a513 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 @@ -16,17 +16,19 @@ import org.gradle.plugins.signing.Sign import org.gradle.plugins.signing.SigningExtension import org.jreleaser.model.Active -private const val PUBLISH_GROUP_NAME_PROP = "publishGroupName" +// TODO: Refactor all of this into env vars ? private const val SKIP_PUBLISH_PROP = "skipPublish" private const val SIGNING_KEY_PROP = "signingKey" private const val SIGNING_PASSWORD_PROP = "signingPassword" +private const val J_RELEASER_STAGE_ENV_VAR = "JRELEASER_MAVENCENTRAL_STAGE" +private const val J_RELEASER_VERSION_ENV_VAR = "JRELEASER_PROJECT_VERSION" +private const val J_RELEASER_GROUP_ENV_VAR = "JRELEASER_PROJECT_JAVA_GROUP_ID" private const val J_RELEASER_MAVEN_CENTRAL_USERNAME_ENV_VAR = "JRELEASER_MAVENCENTRAL_USERNAME" private const val J_RELEASER_MAVEN_CENTRAL_TOKEN_ENV_VAR = "JRELEASER_MAVENCENTRAL_TOKEN" +private const val J_RELEASER_GPG_PASSPHRASE_ENV_VAR = "JRELEASER_GPG_PASSPHRASE" private const val J_RELEASER_GPG_PUBLIC_KEY_ENV_VAR = "JRELEASER_GPG_PUBLIC_KEY" private const val J_RELEASER_GPG_SECRET_KEY_ENV_VAR = "JRELEASER_GPG_SECRET_KEY" -private const val J_RELEASER_GPG_PASSPHRASE_ENV_VAR = "JRELEASER_GPG_PASSPHRASE" -private const val J_RELEASER_ENV_VAR = "JRELEASER_PROJECT_JAVA_GROUP_ID" // Names of publications that are allowed to be published private val ALLOWED_PUBLICATIONS = listOf( @@ -146,13 +148,14 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = " fun Project.configureJReleaser() { verifyRootProject { "JReleaser configuration must be applied to the root project only" } listOf( + J_RELEASER_STAGE_ENV_VAR, + J_RELEASER_VERSION_ENV_VAR, + J_RELEASER_GROUP_ENV_VAR, J_RELEASER_MAVEN_CENTRAL_USERNAME_ENV_VAR, J_RELEASER_MAVEN_CENTRAL_TOKEN_ENV_VAR, J_RELEASER_GPG_PASSPHRASE_ENV_VAR, - J_RELEASER_GPG_SECRET_KEY_ENV_VAR, J_RELEASER_GPG_PUBLIC_KEY_ENV_VAR, - J_RELEASER_ENV_VAR, - "JRELEASER_PROJECT_VERSION", // TODO: Keep ? + J_RELEASER_GPG_SECRET_KEY_ENV_VAR, ).map { variable -> if (System.getenv(variable) == null) { logger.warn("Skipping JReleaser configuration, missing required env var: $variable") @@ -164,6 +167,9 @@ fun Project.configureJReleaser() { apply(plugin = "org.jreleaser") extensions.configure { + project { + version = System.getenv(J_RELEASER_VERSION_ENV_VAR) + } signing { active = Active.ALWAYS armored = true @@ -173,9 +179,8 @@ fun Project.configureJReleaser() { mavenCentral { create("maven-central") { active = Active.ALWAYS - url = "https://central.sonatype.com/api/v1/publisher" // TODO: Use `gr jreleaserDeploy` -// sign = true // TODO: Remove me if unnecessary - stagingRepository("target/staging-deploy") + url = "https://central.sonatype.com/api/v1/publisher" + stagingRepository(rootProject.layout.buildDirectory.dir("m2").get().toString()) // TODO: Commonize between this and above } } } @@ -190,7 +195,7 @@ private fun isAvailableForPublication(project: Project, publication: MavenPublic if (project.extra.has(SKIP_PUBLISH_PROP)) shouldPublish = false // Validate publishGroupName - val publishGroupName = project.findProperty(PUBLISH_GROUP_NAME_PROP) as? String + val publishGroupName = System.getenv(J_RELEASER_GROUP_ENV_VAR) // TODO: Check if env var is available ? shouldPublish = shouldPublish && (publishGroupName == null || publication.groupId.startsWith(publishGroupName)) // Validate publication name is allowed to be published From 5d265430b8e83f6afc73be08db6f7b473b0bdc72 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Tue, 1 Jul 2025 15:43:45 -0400 Subject: [PATCH 03/10] finalize --- .../aws/sdk/kotlin/gradle/dsl/Publish.kt | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 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 8209a513..9ea8e9d8 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 @@ -16,13 +16,11 @@ import org.gradle.plugins.signing.Sign import org.gradle.plugins.signing.SigningExtension import org.jreleaser.model.Active -// TODO: Refactor all of this into env vars ? +// Props private const val SKIP_PUBLISH_PROP = "skipPublish" -private const val SIGNING_KEY_PROP = "signingKey" -private const val SIGNING_PASSWORD_PROP = "signingPassword" +// Env vars private const val J_RELEASER_STAGE_ENV_VAR = "JRELEASER_MAVENCENTRAL_STAGE" -private const val J_RELEASER_VERSION_ENV_VAR = "JRELEASER_PROJECT_VERSION" private const val J_RELEASER_GROUP_ENV_VAR = "JRELEASER_PROJECT_JAVA_GROUP_ID" private const val J_RELEASER_MAVEN_CENTRAL_USERNAME_ENV_VAR = "JRELEASER_MAVENCENTRAL_USERNAME" private const val J_RELEASER_MAVEN_CENTRAL_TOKEN_ENV_VAR = "JRELEASER_MAVENCENTRAL_TOKEN" @@ -63,7 +61,7 @@ fun Project.skipPublishing() { * @param repoName the repository name (e.g. `smithy-kotlin`, `aws-sdk-kotlin`, etc) * @param githubOrganization the name of the GitHub organization that [repoName] is located in */ -fun Project.configurePublishing(repoName: String, githubOrganization: String = "awslabs") { // TODO: USE ENV VARS NOW ? +fun Project.configurePublishing(repoName: String, githubOrganization: String = "awslabs") { val project = this apply(plugin = "maven-publish") @@ -113,12 +111,15 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = " } } - if (project.hasProperty(SIGNING_KEY_PROP) && project.hasProperty(SIGNING_PASSWORD_PROP)) { + val gpgSecretKey = System.getenv(J_RELEASER_GPG_SECRET_KEY_ENV_VAR) + val gpgPassphrase = System.getenv(J_RELEASER_GPG_PASSPHRASE_ENV_VAR) + + if (!gpgPassphrase.isNullOrBlank() && !gpgSecretKey.isNullOrBlank()) { apply(plugin = "signing") extensions.configure { useInMemoryPgpKeys( - project.property(SIGNING_KEY_PROP) as String, - project.property(SIGNING_PASSWORD_PROP) as String, + gpgSecretKey, + gpgPassphrase, ) sign(publications) } @@ -147,28 +148,31 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = " */ fun Project.configureJReleaser() { verifyRootProject { "JReleaser configuration must be applied to the root project only" } + + var missingEnvVars = false listOf( J_RELEASER_STAGE_ENV_VAR, - J_RELEASER_VERSION_ENV_VAR, J_RELEASER_GROUP_ENV_VAR, J_RELEASER_MAVEN_CENTRAL_USERNAME_ENV_VAR, J_RELEASER_MAVEN_CENTRAL_TOKEN_ENV_VAR, J_RELEASER_GPG_PASSPHRASE_ENV_VAR, J_RELEASER_GPG_PUBLIC_KEY_ENV_VAR, J_RELEASER_GPG_SECRET_KEY_ENV_VAR, - ).map { variable -> - if (System.getenv(variable) == null) { - logger.warn("Skipping JReleaser configuration, missing required env var: $variable") - true - } else { - false + ).forEach { + if (System.getenv(it).isNullOrBlank()) { + missingEnvVars = true + logger.warn("Skipping JReleaser configuration, missing or blank required env var: $it") } - }.any { return } + } + if (missingEnvVars) return + + // Get SDK version from gradle.properties + val sdkVersion: String by project apply(plugin = "org.jreleaser") extensions.configure { project { - version = System.getenv(J_RELEASER_VERSION_ENV_VAR) + version = sdkVersion } signing { active = Active.ALWAYS @@ -180,7 +184,7 @@ fun Project.configureJReleaser() { create("maven-central") { active = Active.ALWAYS url = "https://central.sonatype.com/api/v1/publisher" - stagingRepository(rootProject.layout.buildDirectory.dir("m2").get().toString()) // TODO: Commonize between this and above + stagingRepository(rootProject.layout.buildDirectory.dir("m2").get().toString()) } } } @@ -195,7 +199,7 @@ private fun isAvailableForPublication(project: Project, publication: MavenPublic if (project.extra.has(SKIP_PUBLISH_PROP)) shouldPublish = false // Validate publishGroupName - val publishGroupName = System.getenv(J_RELEASER_GROUP_ENV_VAR) // TODO: Check if env var is available ? + val publishGroupName = System.getenv(J_RELEASER_GROUP_ENV_VAR) shouldPublish = shouldPublish && (publishGroupName == null || publication.groupId.startsWith(publishGroupName)) // Validate publication name is allowed to be published From 01cd410da405301f2fffb4cd2cb39d6b80b60fd2 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Tue, 1 Jul 2025 16:50:37 -0400 Subject: [PATCH 04/10] checkpoint --- build-plugins/build-support/build.gradle.kts | 1 - .../kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt | 15 ++++++++++++++- gradle/libs.versions.toml | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/build-plugins/build-support/build.gradle.kts b/build-plugins/build-support/build.gradle.kts index fa16f951..a95dda6a 100644 --- a/build-plugins/build-support/build.gradle.kts +++ b/build-plugins/build-support/build.gradle.kts @@ -24,7 +24,6 @@ dependencies { exclude(group = "org.jetbrains.kotlin", module = "kotlin-compiler-embeddable") } - implementation(libs.nexusPublishPlugin) implementation(libs.jReleaserPlugin) compileOnly(gradleApi()) implementation(libs.aws.sdk.s3) 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 9ea8e9d8..a51914fc 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 @@ -5,7 +5,6 @@ package aws.sdk.kotlin.gradle.dsl import aws.sdk.kotlin.gradle.util.verifyRootProject -import org.jreleaser.gradle.plugin.JReleaserExtension import org.gradle.api.Project import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.maven.MavenPublication @@ -14,6 +13,7 @@ import org.gradle.api.tasks.bundling.Jar import org.gradle.kotlin.dsl.* import org.gradle.plugins.signing.Sign import org.gradle.plugins.signing.SigningExtension +import org.jreleaser.gradle.plugin.JReleaserExtension import org.jreleaser.model.Active // Props @@ -141,6 +141,19 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = " } } } + + /* + Creates a dummy JAR for version catalog publishing + The `version-catalog` plugin doesn't generate one because it isn't needed but JReleaser requires a jar to be present in the version catalog component + https://docs.gradle.org/current/userguide/version_catalogs.html#sec:version-catalog-plugin + + Consuming published version catalogs with the dummy JAR still work + https://docs.gradle.org/current/userguide/version_catalogs.html#sec:importing-published-catalog + */ + tasks.register("versionCatalogJar") { + archiveBaseName.set("version-catalog") + from("gradle/libs.versions.toml") + } } /** diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3baf7029..d84bb581 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,7 +13,7 @@ aws-sdk-s3 = { module = "aws.sdk.kotlin:s3", version.ref = "aws-sdk-version" } ktlint-cli = { module = "com.pinterest.ktlint:ktlint-cli", version.ref = "ktlint" } ktlint-cli-ruleset-core = { module = "com.pinterest.ktlint:ktlint-cli-ruleset-core", version.ref = "ktlint" } ktlint-test = {module = "com.pinterest.ktlint:ktlint-test", version.ref = "ktlint" } -jReleaserPlugin = { module = "org.jreleaser:jreleaser-gradle-plugin", version = "jreleaser-plugin-version" } +jReleaserPlugin = { module = "org.jreleaser:jreleaser-gradle-plugin", version.ref = "jreleaser-plugin-version" } smithy-model = { module = "software.amazon.smithy:smithy-model", version.ref = "smithy-version" } smithy-gradle-base-plugin = { module = "software.amazon.smithy.gradle:smithy-base", version.ref = "smithy-gradle-plugin-version" } From 0a15435a83aec8db7da028bd19cd0b7ad1d4fcc4 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Wed, 9 Jul 2025 17:33:11 -0400 Subject: [PATCH 05/10] misc: clean up and system properties --- .../aws/sdk/kotlin/gradle/dsl/Publish.kt | 74 +++++++++---------- 1 file changed, 36 insertions(+), 38 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 a51914fc..e11137ac 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 @@ -16,20 +16,21 @@ import org.gradle.plugins.signing.SigningExtension import org.jreleaser.gradle.plugin.JReleaserExtension import org.jreleaser.model.Active -// Props -private const val SKIP_PUBLISH_PROP = "skipPublish" - -// Env vars -private const val J_RELEASER_STAGE_ENV_VAR = "JRELEASER_MAVENCENTRAL_STAGE" -private const val J_RELEASER_GROUP_ENV_VAR = "JRELEASER_PROJECT_JAVA_GROUP_ID" -private const val J_RELEASER_MAVEN_CENTRAL_USERNAME_ENV_VAR = "JRELEASER_MAVENCENTRAL_USERNAME" -private const val J_RELEASER_MAVEN_CENTRAL_TOKEN_ENV_VAR = "JRELEASER_MAVENCENTRAL_TOKEN" -private const val J_RELEASER_GPG_PASSPHRASE_ENV_VAR = "JRELEASER_GPG_PASSPHRASE" -private const val J_RELEASER_GPG_PUBLIC_KEY_ENV_VAR = "JRELEASER_GPG_PUBLIC_KEY" -private const val J_RELEASER_GPG_SECRET_KEY_ENV_VAR = "JRELEASER_GPG_SECRET_KEY" - -// Names of publications that are allowed to be published -private val ALLOWED_PUBLICATIONS = listOf( +private object SystemProperties { + const val SKIP_PUBLISHING = "skipPublish" + + object JReleaser { + const val STAGE = "jreleaser.mavencentral.stage" + const val GROUP_ID = "jreleaser.project.java.group.id" + const val MAVEN_CENTRAL_USERNAME = "jreleaser.mavencentral.username" + const val MAVEN_CENTRAL_TOKEN = "jreleaser.mavencentral.token" + 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" + } +} + +private val ALLOWED_PUBLICATION_NAMES = setOf( "common", "jvm", "metadata", @@ -52,7 +53,7 @@ private val ALLOWED_PUBLICATIONS = listOf( * Mark this project as excluded from publishing */ fun Project.skipPublishing() { - extra.set(SKIP_PUBLISH_PROP, true) + extra.set(SystemProperties.SKIP_PUBLISHING, true) } /** @@ -111,15 +112,12 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = " } } - val gpgSecretKey = System.getenv(J_RELEASER_GPG_SECRET_KEY_ENV_VAR) - val gpgPassphrase = System.getenv(J_RELEASER_GPG_PASSPHRASE_ENV_VAR) - - if (!gpgPassphrase.isNullOrBlank() && !gpgSecretKey.isNullOrBlank()) { + if (project.hasProperty(SystemProperties.JReleaser.GPG_SECRET_KEY) && project.hasProperty(SystemProperties.JReleaser.GPG_PASSPHRASE)) { apply(plugin = "signing") extensions.configure { useInMemoryPgpKeys( - gpgSecretKey, - gpgPassphrase, + project.property(SystemProperties.JReleaser.GPG_SECRET_KEY) as String, + project.property(SystemProperties.JReleaser.GPG_PASSPHRASE) as String, ) sign(publications) } @@ -143,8 +141,8 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = " } /* - Creates a dummy JAR for version catalog publishing - The `version-catalog` plugin doesn't generate one because it isn't needed but JReleaser requires a jar to be present in the version catalog component + Creates a dummy JAR for the version catalog + The `version-catalog` plugin doesn't generate one because it isn't needed but JReleaser requires a jar for publishing https://docs.gradle.org/current/userguide/version_catalogs.html#sec:version-catalog-plugin Consuming published version catalogs with the dummy JAR still work @@ -152,7 +150,7 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = " */ tasks.register("versionCatalogJar") { archiveBaseName.set("version-catalog") - from("gradle/libs.versions.toml") + from("gradle/libs.versions.toml") // Could be anything } } @@ -162,22 +160,22 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = " fun Project.configureJReleaser() { verifyRootProject { "JReleaser configuration must be applied to the root project only" } - var missingEnvVars = false + var missingSystemProperties = false listOf( - J_RELEASER_STAGE_ENV_VAR, - J_RELEASER_GROUP_ENV_VAR, - J_RELEASER_MAVEN_CENTRAL_USERNAME_ENV_VAR, - J_RELEASER_MAVEN_CENTRAL_TOKEN_ENV_VAR, - J_RELEASER_GPG_PASSPHRASE_ENV_VAR, - J_RELEASER_GPG_PUBLIC_KEY_ENV_VAR, - J_RELEASER_GPG_SECRET_KEY_ENV_VAR, + SystemProperties.JReleaser.STAGE, + SystemProperties.JReleaser.GROUP_ID, + SystemProperties.JReleaser.MAVEN_CENTRAL_USERNAME, + SystemProperties.JReleaser.MAVEN_CENTRAL_TOKEN, + SystemProperties.JReleaser.GPG_PASSPHRASE, + SystemProperties.JReleaser.GPG_PUBLIC_KEY, + SystemProperties.JReleaser.GPG_SECRET_KEY, ).forEach { - if (System.getenv(it).isNullOrBlank()) { - missingEnvVars = true + if (!project.hasProperty(it)) { + missingSystemProperties = true logger.warn("Skipping JReleaser configuration, missing or blank required env var: $it") } } - if (missingEnvVars) return + if (missingSystemProperties) return // Get SDK version from gradle.properties val sdkVersion: String by project @@ -209,14 +207,14 @@ private fun isAvailableForPublication(project: Project, publication: MavenPublic var shouldPublish = true // Check SKIP_PUBLISH_PROP - if (project.extra.has(SKIP_PUBLISH_PROP)) shouldPublish = false + if (project.extra.has(SystemProperties.SKIP_PUBLISHING)) shouldPublish = false // Validate publishGroupName - val publishGroupName = System.getenv(J_RELEASER_GROUP_ENV_VAR) + val publishGroupName = System.getenv(SystemProperties.JReleaser.GROUP_ID) shouldPublish = shouldPublish && (publishGroupName == null || publication.groupId.startsWith(publishGroupName)) // Validate publication name is allowed to be published - shouldPublish = shouldPublish && ALLOWED_PUBLICATIONS.any { publication.name.equals(it, ignoreCase = true) } + shouldPublish = shouldPublish && ALLOWED_PUBLICATION_NAMES.any { publication.name.equals(it, ignoreCase = true) } return shouldPublish } From 16007475421df020dba4c017673e5a4577d2d446 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Thu, 10 Jul 2025 10:34:50 -0400 Subject: [PATCH 06/10] misc: self review --- .../src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt | 4 +--- 1 file changed, 1 insertion(+), 3 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 e11137ac..1951e59e 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 @@ -20,7 +20,6 @@ private object SystemProperties { const val SKIP_PUBLISHING = "skipPublish" object JReleaser { - const val STAGE = "jreleaser.mavencentral.stage" const val GROUP_ID = "jreleaser.project.java.group.id" const val MAVEN_CENTRAL_USERNAME = "jreleaser.mavencentral.username" const val MAVEN_CENTRAL_TOKEN = "jreleaser.mavencentral.token" @@ -162,7 +161,6 @@ fun Project.configureJReleaser() { var missingSystemProperties = false listOf( - SystemProperties.JReleaser.STAGE, SystemProperties.JReleaser.GROUP_ID, SystemProperties.JReleaser.MAVEN_CENTRAL_USERNAME, SystemProperties.JReleaser.MAVEN_CENTRAL_TOKEN, @@ -172,7 +170,7 @@ fun Project.configureJReleaser() { ).forEach { if (!project.hasProperty(it)) { missingSystemProperties = true - logger.warn("Skipping JReleaser configuration, missing or blank required env var: $it") + logger.warn("Skipping JReleaser configuration, missing required system property: $it") } } if (missingSystemProperties) return From ba0cc48d18a76bd0222b141407e16e43cabc659d Mon Sep 17 00:00:00 2001 From: 0marperez Date: Tue, 15 Jul 2025 10:43:59 -0400 Subject: [PATCH 07/10] properties to env vars --- .../aws/sdk/kotlin/gradle/dsl/Publish.kt | 56 ++++++++++--------- 1 file changed, 30 insertions(+), 26 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 1951e59e..2175684b 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 @@ -16,16 +16,18 @@ import org.gradle.plugins.signing.SigningExtension import org.jreleaser.gradle.plugin.JReleaserExtension import org.jreleaser.model.Active -private object SystemProperties { +private object Properties { const val SKIP_PUBLISHING = "skipPublish" +} +private object EnvironmentVariables { object JReleaser { - const val GROUP_ID = "jreleaser.project.java.group.id" - const val MAVEN_CENTRAL_USERNAME = "jreleaser.mavencentral.username" - const val MAVEN_CENTRAL_TOKEN = "jreleaser.mavencentral.token" - 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 GROUP_ID = "JRELEASER_PROJECT_JAVA_GROUP_ID" + const val MAVEN_CENTRAL_USERNAME = "JRELEASER_MAVENCENTRAL_USERNAME" + const val MAVEN_CENTRAL_TOKEN = "JRELEASER_MAVENCENTRAL_TOKEN" + 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" } } @@ -52,7 +54,7 @@ private val ALLOWED_PUBLICATION_NAMES = setOf( * Mark this project as excluded from publishing */ fun Project.skipPublishing() { - extra.set(SystemProperties.SKIP_PUBLISHING, true) + extra.set(Properties.SKIP_PUBLISHING, true) } /** @@ -111,12 +113,15 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = " } } - if (project.hasProperty(SystemProperties.JReleaser.GPG_SECRET_KEY) && project.hasProperty(SystemProperties.JReleaser.GPG_PASSPHRASE)) { + val secretKey = System.getenv(EnvironmentVariables.JReleaser.GPG_SECRET_KEY) + val passphrase = System.getenv(EnvironmentVariables.JReleaser.GPG_PASSPHRASE) + + if (!secretKey.isNullOrBlank() && !passphrase.isNullOrBlank()) { apply(plugin = "signing") extensions.configure { useInMemoryPgpKeys( - project.property(SystemProperties.JReleaser.GPG_SECRET_KEY) as String, - project.property(SystemProperties.JReleaser.GPG_PASSPHRASE) as String, + secretKey, + passphrase, ) sign(publications) } @@ -140,7 +145,7 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = " } /* - Creates a dummy JAR for the version catalog + Creates a placeholder JAR for the version catalog The `version-catalog` plugin doesn't generate one because it isn't needed but JReleaser requires a jar for publishing https://docs.gradle.org/current/userguide/version_catalogs.html#sec:version-catalog-plugin @@ -159,21 +164,20 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = " fun Project.configureJReleaser() { verifyRootProject { "JReleaser configuration must be applied to the root project only" } - var missingSystemProperties = false + var missingVariables = false listOf( - SystemProperties.JReleaser.GROUP_ID, - SystemProperties.JReleaser.MAVEN_CENTRAL_USERNAME, - SystemProperties.JReleaser.MAVEN_CENTRAL_TOKEN, - SystemProperties.JReleaser.GPG_PASSPHRASE, - SystemProperties.JReleaser.GPG_PUBLIC_KEY, - SystemProperties.JReleaser.GPG_SECRET_KEY, + EnvironmentVariables.JReleaser.MAVEN_CENTRAL_USERNAME, + EnvironmentVariables.JReleaser.MAVEN_CENTRAL_TOKEN, + EnvironmentVariables.JReleaser.GPG_PASSPHRASE, + EnvironmentVariables.JReleaser.GPG_PUBLIC_KEY, + EnvironmentVariables.JReleaser.GPG_SECRET_KEY, ).forEach { - if (!project.hasProperty(it)) { - missingSystemProperties = true - logger.warn("Skipping JReleaser configuration, missing required system property: $it") + if (System.getenv(it).isNullOrBlank()) { + missingVariables = true + logger.warn("Skipping JReleaser configuration, missing required environment variable: $it") } } - if (missingSystemProperties) return + if (missingVariables) return // Get SDK version from gradle.properties val sdkVersion: String by project @@ -205,10 +209,10 @@ private fun isAvailableForPublication(project: Project, publication: MavenPublic var shouldPublish = true // Check SKIP_PUBLISH_PROP - if (project.extra.has(SystemProperties.SKIP_PUBLISHING)) shouldPublish = false + if (project.extra.has(Properties.SKIP_PUBLISHING)) shouldPublish = false - // Validate publishGroupName - val publishGroupName = System.getenv(SystemProperties.JReleaser.GROUP_ID) + // Only publish publications with the configured group from JReleaser or everything if JReleaser group is not configured + val publishGroupName = System.getenv(EnvironmentVariables.JReleaser.GROUP_ID) shouldPublish = shouldPublish && (publishGroupName == null || publication.groupId.startsWith(publishGroupName)) // Validate publication name is allowed to be published From 87d5f4dfb036017a295cc627c97645c51ca57d07 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Tue, 15 Jul 2025 10:51:06 -0400 Subject: [PATCH 08/10] self review --- .../src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt | 7 ++----- 1 file changed, 2 insertions(+), 5 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 2175684b..02c9a79e 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 @@ -146,15 +146,12 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = " /* Creates a placeholder JAR for the version catalog - The `version-catalog` plugin doesn't generate one because it isn't needed but JReleaser requires a jar for publishing + The `version-catalog` plugin doesn't generate one because it isn't needed but JReleaser requires a jar https://docs.gradle.org/current/userguide/version_catalogs.html#sec:version-catalog-plugin - - Consuming published version catalogs with the dummy JAR still work - https://docs.gradle.org/current/userguide/version_catalogs.html#sec:importing-published-catalog */ tasks.register("versionCatalogJar") { archiveBaseName.set("version-catalog") - from("gradle/libs.versions.toml") // Could be anything + from("gradle/libs.versions.toml") } } From d48fce5938265b421e336c28c7c0b12a37db965d Mon Sep 17 00:00:00 2001 From: 0marperez Date: Thu, 17 Jul 2025 16:34:39 -0400 Subject: [PATCH 09/10] misc: configure version catalog in jreleaser --- .../kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 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 02c9a79e..cbe7dfda 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 @@ -143,16 +143,6 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = " } } } - - /* - Creates a placeholder JAR for the version catalog - The `version-catalog` plugin doesn't generate one because it isn't needed but JReleaser requires a jar - https://docs.gradle.org/current/userguide/version_catalogs.html#sec:version-catalog-plugin - */ - tasks.register("versionCatalogJar") { - archiveBaseName.set("version-catalog") - from("gradle/libs.versions.toml") - } } /** @@ -195,6 +185,13 @@ fun Project.configureJReleaser() { 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 + } + } } } } From a42d596ef32acacca80ce0abf353ce982134fe13 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Thu, 17 Jul 2025 16:51:19 -0400 Subject: [PATCH 10/10] review feedback --- .../aws/sdk/kotlin/gradle/dsl/Publish.kt | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 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 cbe7dfda..ab69c295 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 @@ -21,14 +21,12 @@ private object Properties { } private object EnvironmentVariables { - object JReleaser { - const val GROUP_ID = "JRELEASER_PROJECT_JAVA_GROUP_ID" - const val MAVEN_CENTRAL_USERNAME = "JRELEASER_MAVENCENTRAL_USERNAME" - const val MAVEN_CENTRAL_TOKEN = "JRELEASER_MAVENCENTRAL_TOKEN" - 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 GROUP_ID = "JRELEASER_PROJECT_JAVA_GROUP_ID" + const val MAVEN_CENTRAL_USERNAME = "JRELEASER_MAVENCENTRAL_USERNAME" + const val MAVEN_CENTRAL_TOKEN = "JRELEASER_MAVENCENTRAL_TOKEN" + 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" } private val ALLOWED_PUBLICATION_NAMES = setOf( @@ -113,8 +111,8 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = " } } - val secretKey = System.getenv(EnvironmentVariables.JReleaser.GPG_SECRET_KEY) - val passphrase = System.getenv(EnvironmentVariables.JReleaser.GPG_PASSPHRASE) + val secretKey = System.getenv(EnvironmentVariables.GPG_SECRET_KEY) + val passphrase = System.getenv(EnvironmentVariables.GPG_PASSPHRASE) if (!secretKey.isNullOrBlank() && !passphrase.isNullOrBlank()) { apply(plugin = "signing") @@ -153,11 +151,11 @@ fun Project.configureJReleaser() { var missingVariables = false listOf( - EnvironmentVariables.JReleaser.MAVEN_CENTRAL_USERNAME, - EnvironmentVariables.JReleaser.MAVEN_CENTRAL_TOKEN, - EnvironmentVariables.JReleaser.GPG_PASSPHRASE, - EnvironmentVariables.JReleaser.GPG_PUBLIC_KEY, - EnvironmentVariables.JReleaser.GPG_SECRET_KEY, + 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 @@ -206,7 +204,7 @@ private fun isAvailableForPublication(project: Project, publication: MavenPublic 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.JReleaser.GROUP_ID) + val publishGroupName = System.getenv(EnvironmentVariables.GROUP_ID) shouldPublish = shouldPublish && (publishGroupName == null || publication.groupId.startsWith(publishGroupName)) // Validate publication name is allowed to be published