diff --git a/.changes/703da74b-6f77-4555-b129-295486571361.json b/.changes/703da74b-6f77-4555-b129-295486571361.json new file mode 100644 index 00000000000..9f8f3a23464 --- /dev/null +++ b/.changes/703da74b-6f77-4555-b129-295486571361.json @@ -0,0 +1,9 @@ +{ + "id": "703da74b-6f77-4555-b129-295486571361", + "type": "feature", + "description": "Publish a BOM and a Version Catalog", + "issues": [ + "awslabs/aws-sdk-kotlin#605", + "awslabs/aws-sdk-kotlin#805" + ] +} \ No newline at end of file diff --git a/bom/build.gradle.kts b/bom/build.gradle.kts new file mode 100644 index 00000000000..3e5939e1a7a --- /dev/null +++ b/bom/build.gradle.kts @@ -0,0 +1,90 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +import aws.sdk.kotlin.gradle.dsl.configurePublishing +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginWrapper +import org.jetbrains.kotlin.gradle.plugin.KotlinTarget +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget +import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget +import java.util.* + +plugins { + `maven-publish` + `java-platform` + `version-catalog` +} + +val sdkVersion: String by project + +group = "aws.sdk.kotlin" +version = sdkVersion + +val evaluateAfter = listOf(":services", ":aws-runtime", ":tests", ":codegen") +evaluateAfter.forEach { evaluationDependsOn(it) } + +fun createBomConstraintsAndVersionCatalog() { + val bomConstraints: DependencyConstraintHandler = dependencies.constraints + val catalogExt = catalog + + rootProject.subprojects { + val subproject = this + val hasMavenPublish = subproject.plugins.hasPlugin("maven-publish") + if (!hasMavenPublish) { + logger.info("skipping bom and version-catalog entry for ${subproject.name}") + return@subprojects + } + subproject.plugins.withType { + subproject.extensions.getByType().targets.all { + val target = this + val gavCoordinates = gav(target) + bomConstraints.api(gavCoordinates) + catalogExt.versionCatalog { + val prefix = when { + subproject.path.contains(":services") -> "services-" + subproject.path.contains(":aws-runtime") -> "runtime-" + else -> "" + } + val alias = prefix + artifactId(target) + library(alias, gavCoordinates) + } + } + } + } +} + +fun Project.artifactId(target: KotlinTarget): String = when (target) { + is KotlinMetadataTarget -> name + is KotlinJsTarget -> "$name-js" + else -> "$name-${target.targetName.toLowerCase(Locale.ROOT)}" +} + +/** + * Returns a string like "aws.sdk.kotlin:s3-linuxx64:1.0.2" for this target. + */ +fun Project.gav(target: KotlinTarget): String { + val artifactId = artifactId(target) + return "$group:$artifactId:$version" +} + +fun DependencyConstraintHandler.api(constraintNotation: Any) = + add("api", constraintNotation) + +createBomConstraintsAndVersionCatalog() + +configurePublishing("aws-sdk-kotlin") + +publishing { + publications { + create("bom", MavenPublication::class) { + artifactId = "bom" + from(project.components.getByName("javaPlatform")) + } + + create("versionCatalog") { + artifactId = "version-catalog" + from(components["versionCatalog"]) + } + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 13c30b4def6..d910c8a8a1a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -37,6 +37,7 @@ rootProject.name = "aws-sdk-kotlin" includeBuild("./gradle/sdk-plugins") include(":dokka-aws") +include(":bom") include(":codegen:sdk") include(":codegen:smithy-aws-kotlin-codegen") include(":codegen:protocol-tests") @@ -45,6 +46,7 @@ include(":aws-runtime:aws-core") include(":aws-runtime:aws-config") include(":aws-runtime:aws-endpoint") include(":aws-runtime:aws-http") +include(":services") include(":tests") include(":tests:benchmarks:service-benchmarks") include(":tests:codegen:event-stream")