Skip to content

Commit 0ef6b50

Browse files
committed
Try using gradle-maven-publish-plugin
1 parent 31859a9 commit 0ef6b50

File tree

5 files changed

+143
-75
lines changed

5 files changed

+143
-75
lines changed

aws-runtime/build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ subprojects {
3232
plugin(libraries.plugins.aws.kotlin.repo.tools.kmp.get().pluginId)
3333
}
3434

35-
configureNexusPublishing("aws-sdk-kotlin")
36-
3735
kotlin {
3836
explicitApi()
3937

build.gradle.kts

Lines changed: 3 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5-
import aws.sdk.kotlin.gradle.dsl.configureNexus
65
import aws.sdk.kotlin.gradle.dsl.configureLinting
76
import aws.sdk.kotlin.gradle.dsl.configureMinorVersionStrategyRules
87
import aws.sdk.kotlin.gradle.util.typedProp
@@ -36,11 +35,11 @@ buildscript {
3635

3736
plugins {
3837
`dokka-convention`
38+
`publishing-convention`
3939
// ensure the correct version of KGP ends up on our buildscript classpath
4040
id(libs.plugins.kotlin.multiplatform.get().pluginId) apply false
4141
id(libs.plugins.kotlin.jvm.get().pluginId) apply false
4242
alias(libs.plugins.aws.kotlin.repo.tools.artifactsizemetrics)
43-
alias(libs.plugins.vanniktech.maven.publish)
4443
}
4544

4645
artifactSizeMetrics {
@@ -76,6 +75,8 @@ allprojects {
7675

7776
// Enables running `./gradlew allDeps` to get a comprehensive list of dependencies for every subproject
7877
tasks.register<DependencyReportTask>("allDeps") { }
78+
79+
plugins.apply("publishing-convention")
7980
}
8081

8182
// Configure root module's documentation
@@ -96,9 +97,6 @@ dependencies {
9697
dokka(project(":hll"))
9798
}
9899

99-
// Publishing
100-
configureNexus()
101-
102100
// Code Style
103101
val lintPaths = listOf(
104102
"**/*.{kt,kts}",
@@ -111,71 +109,3 @@ val lintPaths = listOf(
111109

112110
configureLinting(lintPaths)
113111
configureMinorVersionStrategyRules(lintPaths)
114-
115-
///**
116-
// * Configure publishing for this project using `com.vanniktech.maven.publish` plugin.
117-
// * @param repoName the repository name (e.g. `smithy-kotlin`, `aws-sdk-kotlin`, etc)
118-
// * @param githubOrganization the name of the GitHub organization that [repoName] is located in
119-
// */
120-
//fun Project.configureVktPublishing(repoName: String, githubOrganization: String = "aws") {
121-
// val project = this
122-
// apply(plugin = "com.vanniktech.maven.publish")
123-
//
124-
// extensions.configure<MavenPublishBaseExtension> {
125-
// // Configure publications
126-
// // https://vanniktech.github.io/gradle-maven-publish-plugin/what/
127-
// configure(KotlinMultiplatform(javadocJar = JavadocJar.Empty(), sourcesJar = true))
128-
// configure(VersionCatalog())
129-
//
130-
// // Configure Maven Central
131-
// publishToMavenCentral(automaticRelease = true)
132-
// signAllPublications()
133-
// // // FIXME Set these secrets during the publish stage
134-
// /*
135-
// ORG_GRADLE_PROJECT_mavenCentralUsername=username
136-
// ORG_GRADLE_PROJECT_mavenCentralPassword=the_password
137-
//
138-
// # see below for how to obtain this
139-
// ORG_GRADLE_PROJECT_signingInMemoryKey=exported_ascii_armored_key
140-
// # Optional
141-
// ORG_GRADLE_PROJECT_signingInMemoryKeyId=12345678
142-
// # If key was created with a password.
143-
// ORG_GRADLE_PROJECT_signingInMemoryKeyPassword=some_password
144-
// */
145-
//
146-
// // coordinates() // FIXME are coordinates required?
147-
//
148-
// pom {
149-
// name = project.name
150-
// description = project.description
151-
// url = "https://github.com/$githubOrganization/$repoName"
152-
// licenses {
153-
// license {
154-
// name = "Apache-2.0"
155-
// url = "https://www.apache.org/licenses/LICENSE-2.0.txt"
156-
// }
157-
// }
158-
// developers {
159-
// developer {
160-
// id.set(repoName)
161-
// name.set("AWS SDK Kotlin Team")
162-
// }
163-
// }
164-
// scm {
165-
// connection.set("scm:git:git://github.com/$githubOrganization/$repoName.git")
166-
// developerConnection.set("scm:git:ssh://github.com/$githubOrganization/$repoName.git")
167-
// url.set("https://github.com/$githubOrganization/$repoName")
168-
// }
169-
// }
170-
// }
171-
// // FIXME Figure out how to conditionally publish projects using isAvailableForPublication
172-
// tasks.withType<AbstractPublishToMaven>().configureEach {
173-
// onlyIf {
174-
// isAvailableForPublication(project, publication).also {
175-
// if (!it) {
176-
// logger.warn("Skipping publication, project=${project.name}; publication=${publication.name}; group=${publication.groupId}")
177-
// }
178-
// }
179-
// }
180-
// }
181-
//}

buildSrc/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ repositories {
1616
dependencies {
1717
implementation(libs.dokka.gradle.plugin)
1818
implementation(libs.kotlin.gradle.plugin)
19+
implementation(libs.vanniktech.maven.publish)
1920
}
2021

2122
dependencies {
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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+
}

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ mockk = { module = "io.mockk:mockk", version.ref = "mockk-version" }
125125

126126
ddb-local = { module = "com.amazonaws:DynamoDBLocal", version.ref = "ddb-local-version" }
127127

128+
vanniktech-maven-publish = { module = "com.vanniktech:gradle-maven-publish-plugin", version = "0.34.0" }
129+
128130
[bundles]
129131
# bundle of smithy-kotlin dependencies all AWS service clients have
130132
smithy-kotlin-service-client = [

0 commit comments

Comments
 (0)