Skip to content

Commit dcba387

Browse files
authored
kn: merge from main, add mingwX64 as an allowed publication (#110)
1 parent 3dfab79 commit dcba387

File tree

4 files changed

+153
-2
lines changed

4 files changed

+153
-2
lines changed

build-plugins/build-support/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ dependencies {
2424
exclude(group = "org.jetbrains.kotlin", module = "kotlin-compiler-embeddable")
2525
}
2626

27-
implementation(libs.jReleaserPlugin)
27+
implementation(libs.nexus.publish.plugin)
28+
implementation(libs.jreleaser.plugin)
2829
compileOnly(gradleApi())
2930
implementation(libs.aws.sdk.s3)
3031
implementation(libs.aws.sdk.cloudwatch)

build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package aws.sdk.kotlin.gradle.dsl
66

77
import aws.sdk.kotlin.gradle.util.verifyRootProject
8+
import io.github.gradlenexus.publishplugin.NexusPublishExtension
89
import org.gradle.api.Project
910
import org.gradle.api.publish.PublishingExtension
1011
import org.gradle.api.publish.maven.MavenPublication
@@ -15,11 +16,19 @@ import org.gradle.plugins.signing.Sign
1516
import org.gradle.plugins.signing.SigningExtension
1617
import org.jreleaser.gradle.plugin.JReleaserExtension
1718
import org.jreleaser.model.Active
19+
import java.time.Duration
1820

1921
private object Properties {
2022
const val SKIP_PUBLISHING = "skipPublish"
2123
}
2224

25+
// TODO Remove once aws-sdk-kotlin migrates to Central Portal
26+
private const val PUBLISH_GROUP_NAME_PROP = "publishGroupName"
27+
private const val SIGNING_KEY_PROP = "signingKey"
28+
private const val SIGNING_PASSWORD_PROP = "signingPassword"
29+
private const val SONATYPE_USERNAME_PROP = "sonatypeUsername"
30+
private const val SONATYPE_PASSWORD_PROP = "sonatypePassword"
31+
2332
private object EnvironmentVariables {
2433
const val GROUP_ID = "JRELEASER_PROJECT_JAVA_GROUP_ID"
2534
const val MAVEN_CENTRAL_USERNAME = "JRELEASER_MAVENCENTRAL_USERNAME"
@@ -39,6 +48,7 @@ private val ALLOWED_PUBLICATION_NAMES = setOf(
3948
"linuxX64",
4049
"macosArm64",
4150
"macosX64",
51+
"mingwX64",
4252

4353
"metadata",
4454
"bom",
@@ -61,6 +71,102 @@ fun Project.skipPublishing() {
6171
extra.set(Properties.SKIP_PUBLISHING, true)
6272
}
6373

74+
// TODO Remove this once aws-sdk-kotlin migrates to Central Portal
75+
fun Project.configureNexusPublishing(repoName: String, githubOrganization: String = "awslabs") {
76+
val project = this
77+
apply(plugin = "maven-publish")
78+
79+
// FIXME: create a real "javadoc" JAR from Dokka output
80+
val javadocJar = tasks.register<Jar>("emptyJar") {
81+
archiveClassifier.set("javadoc")
82+
destinationDirectory.set(layout.buildDirectory.dir("libs"))
83+
from()
84+
}
85+
86+
extensions.configure<PublishingExtension> {
87+
repositories {
88+
maven {
89+
name = "testLocal"
90+
url = rootProject.layout.buildDirectory.dir("m2").get().asFile.toURI()
91+
}
92+
}
93+
94+
publications.all {
95+
if (this !is MavenPublication) return@all
96+
97+
project.afterEvaluate {
98+
pom {
99+
name.set(project.name)
100+
description.set(project.description)
101+
url.set("https://github.com/$githubOrganization/$repoName")
102+
licenses {
103+
license {
104+
name.set("Apache-2.0")
105+
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
106+
}
107+
}
108+
developers {
109+
developer {
110+
id.set(repoName)
111+
name.set("AWS SDK Kotlin Team")
112+
}
113+
}
114+
scm {
115+
connection.set("scm:git:git://github.com/$githubOrganization/$repoName.git")
116+
developerConnection.set("scm:git:ssh://github.com/$githubOrganization/$repoName.git")
117+
url.set("https://github.com/$githubOrganization/$repoName")
118+
}
119+
120+
artifact(javadocJar)
121+
}
122+
}
123+
}
124+
125+
if (project.hasProperty(SIGNING_KEY_PROP) && project.hasProperty(SIGNING_PASSWORD_PROP)) {
126+
apply(plugin = "signing")
127+
extensions.configure<SigningExtension> {
128+
useInMemoryPgpKeys(
129+
project.property(SIGNING_KEY_PROP) as String,
130+
project.property(SIGNING_PASSWORD_PROP) as String,
131+
)
132+
sign(publications)
133+
}
134+
135+
// FIXME - workaround for https://github.com/gradle/gradle/issues/26091
136+
val signingTasks = tasks.withType<Sign>()
137+
tasks.withType<AbstractPublishToMaven>().configureEach {
138+
mustRunAfter(signingTasks)
139+
}
140+
}
141+
}
142+
143+
fun isAvailableForNexusPublication(project: Project, publication: MavenPublication): Boolean {
144+
var shouldPublish = true
145+
146+
// Check SKIP_PUBLISH_PROP
147+
if (project.extra.has(Properties.SKIP_PUBLISHING)) shouldPublish = false
148+
149+
// Only publish publications with the configured group from JReleaser or everything if JReleaser group is not configured
150+
val publishGroupName = project.findProperty(PUBLISH_GROUP_NAME_PROP) as? String
151+
shouldPublish = shouldPublish && (publishGroupName == null || publication.groupId.startsWith(publishGroupName))
152+
153+
// Validate publication name is allowed to be published
154+
shouldPublish = shouldPublish && ALLOWED_PUBLICATION_NAMES.any { publication.name.equals(it, ignoreCase = true) }
155+
156+
return shouldPublish
157+
}
158+
159+
tasks.withType<AbstractPublishToMaven>().configureEach {
160+
onlyIf {
161+
isAvailableForNexusPublication(project, publication).also {
162+
if (!it) {
163+
logger.warn("Skipping publication, project=${project.name}; publication=${publication.name}; group=${publication.groupId}")
164+
}
165+
}
166+
}
167+
}
168+
}
169+
64170
/**
65171
* Configure publishing for this project. This applies the `maven-publish` and `signing` plugins and configures
66172
* the publications.
@@ -149,6 +255,43 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = "
149255
}
150256
}
151257

258+
/**
259+
* Configure nexus publishing plugin. This (conditionally) enables the `gradle-nexus.publish-plugin` and configures it.
260+
*/
261+
fun Project.configureNexus(
262+
nexusUrl: String = "https://ossrh-staging-api.central.sonatype.com/service/local/",
263+
snapshotRepositoryUrl: String = "https://central.sonatype.com/repository/maven-snapshots/",
264+
) {
265+
verifyRootProject { "Kotlin SDK nexus configuration must be applied to the root project only" }
266+
267+
val requiredProps = listOf(SONATYPE_USERNAME_PROP, SONATYPE_PASSWORD_PROP, PUBLISH_GROUP_NAME_PROP)
268+
val doConfigure = requiredProps.all { project.hasProperty(it) }
269+
if (!doConfigure) {
270+
logger.info("skipping nexus configuration, missing one or more required properties: $requiredProps")
271+
return
272+
}
273+
274+
apply(plugin = "io.github.gradle-nexus.publish-plugin")
275+
extensions.configure<NexusPublishExtension> {
276+
val publishGroupName = project.property(PUBLISH_GROUP_NAME_PROP) as String
277+
group = publishGroupName
278+
packageGroup.set(publishGroupName)
279+
repositories {
280+
create("awsNexus") {
281+
this.nexusUrl.set(uri(nexusUrl))
282+
this.snapshotRepositoryUrl.set(uri(snapshotRepositoryUrl))
283+
username.set(project.property(SONATYPE_USERNAME_PROP) as String)
284+
password.set(project.property(SONATYPE_PASSWORD_PROP) as String)
285+
}
286+
}
287+
288+
transitionCheckOptions {
289+
maxRetries.set(180)
290+
delayBetween.set(Duration.ofSeconds(10))
291+
}
292+
}
293+
}
294+
152295
/**
153296
* Configure JReleaser publishing plugin. This (conditionally) enables the `org.jreleaser` plugin and configures it.
154297
*/

build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ if (releaseVersion == null) logger.warn("no release version set")
1313
val s3Url = propertyOrEnv("release.s3.url", "RELEASE_S3_URL")
1414
if (s3Url == null) logger.warn("S3 repository not configured, missing S3 url")
1515

16+
allprojects {
17+
// Enables running `./gradlew allDeps` to get a comprehensive list of dependencies for every subproject
18+
tasks.register<DependencyReportTask>("allDeps") { }
19+
}
20+
1621
subprojects {
1722
group = "aws.sdk.kotlin.gradle"
1823
version = releaseVersion ?: "0.0.1"

gradle/libs.versions.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
aws-sdk-version = "1.4.116"
33
kotlin-version = "2.2.0"
44
ktlint = "1.3.0"
5+
nexus-plugin-version = "2.0.0"
56
jreleaser-plugin-version = "1.18.0"
67
publish-plugin-version = "1.3.1"
78
smithy-version = "1.60.2"
@@ -14,7 +15,8 @@ aws-sdk-s3 = { module = "aws.sdk.kotlin:s3", version.ref = "aws-sdk-version" }
1415
ktlint-cli = { module = "com.pinterest.ktlint:ktlint-cli", version.ref = "ktlint" }
1516
ktlint-cli-ruleset-core = { module = "com.pinterest.ktlint:ktlint-cli-ruleset-core", version.ref = "ktlint" }
1617
ktlint-test = {module = "com.pinterest.ktlint:ktlint-test", version.ref = "ktlint" }
17-
jReleaserPlugin = { module = "org.jreleaser:jreleaser-gradle-plugin", version.ref = "jreleaser-plugin-version" }
18+
nexus-publish-plugin = { module = "io.github.gradle-nexus:publish-plugin", version.ref = "nexus-plugin-version" }
19+
jreleaser-plugin = { module = "org.jreleaser:jreleaser-gradle-plugin", version.ref = "jreleaser-plugin-version" }
1820
smithy-model = { module = "software.amazon.smithy:smithy-model", version.ref = "smithy-version" }
1921
smithy-gradle-base-plugin = { module = "software.amazon.smithy.gradle:smithy-base", version.ref = "smithy-gradle-plugin-version" }
2022

0 commit comments

Comments
 (0)