1+ /*
2+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+ * SPDX-License-Identifier: Apache-2.0
4+ */
5+
6+ import com.vanniktech.maven.publish.JavadocJar
7+ import com.vanniktech.maven.publish.KotlinMultiplatform
8+ import com.vanniktech.maven.publish.VersionCatalog
9+ import com.vanniktech.maven.publish.MavenPublishBaseExtension
10+
11+ plugins {
12+ id(" com.vanniktech.maven.publish" )
13+ }
14+
15+ extensions.configure<MavenPublishBaseExtension > {
16+ println (" Configuring gradle-maven-publish-plugin for ${project.name} " )
17+ // Configure publications
18+ // https://vanniktech.github.io/gradle-maven-publish-plugin/what/
19+ if (project.plugins.hasPlugin(" org.jetbrains.kotlin.multiplatform" )) {
20+ println (" Configuring KotlinMultiplatform publication" )
21+ configure(KotlinMultiplatform (javadocJar = JavadocJar .Empty (), sourcesJar = true ))
22+ }
23+ if (project.plugins.hasPlugin(" version-catalog" )) {
24+ println (" Configuring VersionCatalog publication" )
25+ configure(VersionCatalog ())
26+ }
27+
28+ // Configure Maven Central
29+ // Setting `automaticRelease` to false enables running `./gradlew publishToMavenCentral` to stage a deployment
30+ // For a full release, run `./gradlew publishAndReleaseToMavenCentral`
31+ publishToMavenCentral(automaticRelease = false )
32+ signAllPublications()
33+
34+ pom {
35+ name = project.name
36+ description = project.description
37+ url = " https://github.com/aws/aws-sdk-kotlin"
38+ licenses {
39+ license {
40+ name = " Apache-2.0"
41+ url = " https://www.apache.org/licenses/LICENSE-2.0.txt"
42+ }
43+ }
44+ developers {
45+ developer {
46+ id.set(" aws-sdk-kotlin" )
47+ name.set(" AWS SDK Kotlin Team" )
48+ }
49+ }
50+ scm {
51+ connection.set(" scm:git:git://github.com/aws/aws-sdk-kotlin.git" )
52+ developerConnection.set(" scm:git:ssh://github.com/aws/aws-sdk-kotlin.git" )
53+ url.set(" https://github.com/aws/aws-sdk-kotlin" )
54+ }
55+ }
56+
57+ // TODO Confirm this works with the new plugin
58+ tasks.withType<AbstractPublishToMaven >().configureEach {
59+ onlyIf {
60+ isAvailableForPublication(project, publication).also {
61+ if (! it) {
62+ println (" Skipping publication, project=${project.name} ; publication=${publication.name} ; group=${publication.groupId} " )
63+ logger.warn(" Skipping publication, project=${project.name} ; publication=${publication.name} ; group=${publication.groupId} " )
64+ }
65+ }
66+ }
67+ }
68+ }
69+
70+ // TODO Remove once commonized in aws-kotlin-repo-tools
71+ internal val ALLOWED_PUBLICATION_NAMES = setOf (
72+ " common" ,
73+ " jvm" ,
74+ " kotlinMultiplatform" ,
75+ " metadata" ,
76+ " bom" ,
77+ " versionCatalog" ,
78+ " codegen" ,
79+ " codegen-testutils" ,
80+
81+ // aws-sdk-kotlin:hll
82+ " hll-codegen" ,
83+ " dynamodb-mapper-codegen" ,
84+ " dynamodb-mapper-schema-generator-plugin" ,
85+ " dynamodb-mapper-schema-codegen" ,
86+ " dynamodb-mapper-schema-generatorPluginMarkerMaven" ,
87+ )
88+
89+ internal val ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES = setOf (
90+ " iosArm64" ,
91+ " iosSimulatorArm64" ,
92+ " iosX64" ,
93+ " linuxArm64" ,
94+ " linuxX64" ,
95+ " macosArm64" ,
96+ " macosX64" ,
97+ " mingwX64" ,
98+ )
99+
100+ // Group names which are allowed to publish K/N artifacts
101+ private val ALLOWED_KOTLIN_NATIVE_GROUP_NAMES = setOf (
102+ " aws.sdk.kotlin.crt" ,
103+ " aws.smithy.kotlin" ,
104+ )
105+
106+ // Optional override to the above set.
107+ // Used to support local development where you want to run publishToMavenLocal in smithy-kotlin, aws-sdk-kotlin.
108+ internal val OVERRIDE_KOTLIN_NATIVE_GROUP_NAME_VALIDATION = " aws.kotlin.native.allowPublication"
109+
110+ public fun <T > ExtraPropertiesExtension.getOrNull (name : String ): T ? {
111+ if (! has(name)) return null
112+ @Suppress(" UNCHECKED_CAST" )
113+ return get(name) as ? T
114+ }
115+
116+ internal fun isAvailableForPublication (project : Project , publication : MavenPublication ): Boolean {
117+ var shouldPublish = true
118+
119+ // Allow overriding K/N publications for local development
120+ val overrideGroupNameValidation = project.extra.getOrNull<String >(OVERRIDE_KOTLIN_NATIVE_GROUP_NAME_VALIDATION ) == " true"
121+
122+ // Validate publication name
123+ if (publication.name in ALLOWED_PUBLICATION_NAMES ) {
124+ // Standard publication
125+ } else if (publication.name in ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES ) {
126+ // Kotlin/Native publication
127+ if (overrideGroupNameValidation && publication.groupId !in ALLOWED_KOTLIN_NATIVE_GROUP_NAMES ) {
128+ println (" Overriding K/N publication, project=${project.name} ; publication=${publication.name} ; group=${publication.groupId} " )
129+ } else {
130+ shouldPublish = publication.groupId in ALLOWED_KOTLIN_NATIVE_GROUP_NAMES
131+ }
132+ } else {
133+ shouldPublish = false
134+ }
135+
136+ return shouldPublish
137+ }
0 commit comments