Skip to content

Commit 3de5489

Browse files
committed
misc: use both jreleaser and nexus publish plugin
1 parent cca23c7 commit 3de5489

File tree

3 files changed

+68
-3
lines changed

3 files changed

+68
-3
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ dependencies {
2525
}
2626

2727
implementation(libs.jReleaserPlugin)
28+
implementation(libs.nexusPublishPlugin)
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: 65 additions & 3 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,9 +16,17 @@ 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"
23+
24+
// Nexus publish plugin properties
25+
const val PUBLISH_GROUP_NAME_PROP = "publishGroupName"
26+
const val SIGNING_KEY_PROP = "signingKey"
27+
const val SIGNING_PASSWORD_PROP = "signingPassword"
28+
const val SONATYPE_USERNAME_PROP = "sonatypeUsername"
29+
const val SONATYPE_PASSWORD_PROP = "sonatypePassword"
2130
}
2231

2332
private object EnvironmentVariables {
@@ -61,7 +70,11 @@ fun Project.skipPublishing() {
6170
* @param repoName the repository name (e.g. `smithy-kotlin`, `aws-sdk-kotlin`, etc)
6271
* @param githubOrganization the name of the GitHub organization that [repoName] is located in
6372
*/
64-
fun Project.configurePublishing(repoName: String, githubOrganization: String = "awslabs") {
73+
fun Project.configurePublishing(
74+
repoName: String,
75+
githubOrganization: String = "awslabs",
76+
useNexusPublishPlugin: Boolean = false, // TODO:
77+
) {
6578
val project = this
6679
apply(plugin = "maven-publish")
6780

@@ -111,8 +124,17 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = "
111124
}
112125
}
113126

114-
val secretKey = System.getenv(EnvironmentVariables.GPG_SECRET_KEY)
115-
val passphrase = System.getenv(EnvironmentVariables.GPG_PASSPHRASE)
127+
val secretKey = if (useNexusPublishPlugin) {
128+
project.property(Properties.SIGNING_KEY_PROP) as String
129+
} else {
130+
System.getenv(EnvironmentVariables.GPG_SECRET_KEY)
131+
}
132+
133+
val passphrase = if (useNexusPublishPlugin) {
134+
project.property(Properties.SIGNING_PASSWORD_PROP) as String
135+
} else {
136+
System.getenv(EnvironmentVariables.GPG_PASSPHRASE)
137+
}
116138

117139
if (!secretKey.isNullOrBlank() && !passphrase.isNullOrBlank()) {
118140
apply(plugin = "signing")
@@ -218,6 +240,46 @@ fun Project.configureJReleaser() {
218240
}
219241
}
220242

243+
/**
244+
* Configure nexus publishing plugin. This (conditionally) enables the `gradle-nexus.publish-plugin` and configures it.
245+
*/
246+
fun Project.configureNexus(
247+
nexusUrl: String = "https://ossrh-staging-api.central.sonatype.com/service/local/",
248+
snapshotRepositoryUrl: String = "https://central.sonatype.com/repository/maven-snapshots/",
249+
) {
250+
verifyRootProject { "Kotlin SDK nexus configuration must be applied to the root project only" }
251+
252+
val requiredProps = listOf(
253+
Properties.SONATYPE_USERNAME_PROP,
254+
Properties.SONATYPE_PASSWORD_PROP,
255+
Properties.PUBLISH_GROUP_NAME_PROP,
256+
)
257+
val doConfigure = requiredProps.all { project.hasProperty(it) }
258+
if (!doConfigure) {
259+
logger.info("skipping nexus configuration, missing one or more required properties: $requiredProps")
260+
return
261+
}
262+
263+
apply(plugin = "io.github.gradle-nexus.publish-plugin")
264+
extensions.configure<NexusPublishExtension> {
265+
val publishGroupName = project.property(Properties.PUBLISH_GROUP_NAME_PROP) as String
266+
group = publishGroupName
267+
packageGroup.set(publishGroupName)
268+
repositories {
269+
create("awsNexus") {
270+
this.nexusUrl.set(uri(nexusUrl))
271+
this.snapshotRepositoryUrl.set(uri(snapshotRepositoryUrl))
272+
username.set(project.property(Properties.SONATYPE_USERNAME_PROP) as String)
273+
password.set(project.property(Properties.SONATYPE_PASSWORD_PROP) as String)
274+
}
275+
}
276+
277+
transitionCheckOptions {
278+
maxRetries.set(180)
279+
delayBetween.set(Duration.ofSeconds(10))
280+
}
281+
}
282+
}
221283
private fun isAvailableForPublication(project: Project, publication: MavenPublication): Boolean {
222284
var shouldPublish = true
223285

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ aws-sdk-version = "1.4.116"
33
kotlin-version = "2.2.0"
44
ktlint = "1.3.0"
55
jreleaser-plugin-version = "1.18.0"
6+
nexus-plugin-version = "2.0.0"
67
publish-plugin-version = "1.3.1"
78
smithy-version = "1.60.2"
89
smithy-gradle-plugin-version = "1.3.0"
@@ -15,6 +16,7 @@ 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" }
1718
jReleaserPlugin = { module = "org.jreleaser:jreleaser-gradle-plugin", version.ref = "jreleaser-plugin-version" }
19+
nexusPublishPlugin = { module = "io.github.gradle-nexus:publish-plugin", version.ref = "nexus-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)