Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build-plugins/build-support/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
}

implementation(libs.jReleaserPlugin)
implementation(libs.nexusPublishPlugin)
compileOnly(gradleApi())
implementation(libs.aws.sdk.s3)
implementation(libs.aws.sdk.cloudwatch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package aws.sdk.kotlin.gradle.dsl

import aws.sdk.kotlin.gradle.util.verifyRootProject
import io.github.gradlenexus.publishplugin.NexusPublishExtension
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
Expand All @@ -15,9 +16,17 @@ import org.gradle.plugins.signing.Sign
import org.gradle.plugins.signing.SigningExtension
import org.jreleaser.gradle.plugin.JReleaserExtension
import org.jreleaser.model.Active
import java.time.Duration

private object Properties {
const val SKIP_PUBLISHING = "skipPublish"

// Nexus publish plugin properties
const val PUBLISH_GROUP_NAME_PROP = "publishGroupName"
const val SIGNING_KEY_PROP = "signingKey"
const val SIGNING_PASSWORD_PROP = "signingPassword"
const val SONATYPE_USERNAME_PROP = "sonatypeUsername"
const val SONATYPE_PASSWORD_PROP = "sonatypePassword"
}

private object EnvironmentVariables {
Expand Down Expand Up @@ -61,7 +70,11 @@ fun Project.skipPublishing() {
* @param repoName the repository name (e.g. `smithy-kotlin`, `aws-sdk-kotlin`, etc)
* @param githubOrganization the name of the GitHub organization that [repoName] is located in
*/
fun Project.configurePublishing(repoName: String, githubOrganization: String = "awslabs") {
fun Project.configurePublishing(
repoName: String,
githubOrganization: String = "awslabs",
useNexusPublishPlugin: Boolean = true,
) {
val project = this
apply(plugin = "maven-publish")

Expand Down Expand Up @@ -111,8 +124,17 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = "
}
}

val secretKey = System.getenv(EnvironmentVariables.GPG_SECRET_KEY)
val passphrase = System.getenv(EnvironmentVariables.GPG_PASSPHRASE)
val secretKey = if (useNexusPublishPlugin) {
project.property(Properties.SIGNING_KEY_PROP) as String
} else {
System.getenv(EnvironmentVariables.GPG_SECRET_KEY)
}

val passphrase = if (useNexusPublishPlugin) {
project.property(Properties.SIGNING_PASSWORD_PROP) as String
} else {
System.getenv(EnvironmentVariables.GPG_PASSPHRASE)
}

if (!secretKey.isNullOrBlank() && !passphrase.isNullOrBlank()) {
apply(plugin = "signing")
Expand Down Expand Up @@ -218,6 +240,46 @@ fun Project.configureJReleaser() {
}
}

/**
* Configure nexus publishing plugin. This (conditionally) enables the `gradle-nexus.publish-plugin` and configures it.
*/
fun Project.configureNexus(
nexusUrl: String = "https://ossrh-staging-api.central.sonatype.com/service/local/",
snapshotRepositoryUrl: String = "https://central.sonatype.com/repository/maven-snapshots/",
) {
verifyRootProject { "Kotlin SDK nexus configuration must be applied to the root project only" }

val requiredProps = listOf(
Properties.SONATYPE_USERNAME_PROP,
Properties.SONATYPE_PASSWORD_PROP,
Properties.PUBLISH_GROUP_NAME_PROP,
)
val doConfigure = requiredProps.all { project.hasProperty(it) }
if (!doConfigure) {
logger.info("skipping nexus configuration, missing one or more required properties: $requiredProps")
return
}

apply(plugin = "io.github.gradle-nexus.publish-plugin")
extensions.configure<NexusPublishExtension> {
val publishGroupName = project.property(Properties.PUBLISH_GROUP_NAME_PROP) as String
group = publishGroupName
packageGroup.set(publishGroupName)
repositories {
create("awsNexus") {
this.nexusUrl.set(uri(nexusUrl))
this.snapshotRepositoryUrl.set(uri(snapshotRepositoryUrl))
username.set(project.property(Properties.SONATYPE_USERNAME_PROP) as String)
password.set(project.property(Properties.SONATYPE_PASSWORD_PROP) as String)
}
}

transitionCheckOptions {
maxRetries.set(180)
delayBetween.set(Duration.ofSeconds(10))
}
}
}
private fun isAvailableForPublication(project: Project, publication: MavenPublication): Boolean {
var shouldPublish = true

Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ aws-sdk-version = "1.4.116"
kotlin-version = "2.2.0"
ktlint = "1.3.0"
jreleaser-plugin-version = "1.18.0"
nexus-plugin-version = "2.0.0"
publish-plugin-version = "1.3.1"
smithy-version = "1.60.2"
smithy-gradle-plugin-version = "1.3.0"
Expand All @@ -15,6 +16,7 @@ ktlint-cli = { module = "com.pinterest.ktlint:ktlint-cli", version.ref = "ktlint
ktlint-cli-ruleset-core = { module = "com.pinterest.ktlint:ktlint-cli-ruleset-core", version.ref = "ktlint" }
ktlint-test = {module = "com.pinterest.ktlint:ktlint-test", version.ref = "ktlint" }
jReleaserPlugin = { module = "org.jreleaser:jreleaser-gradle-plugin", version.ref = "jreleaser-plugin-version" }
nexusPublishPlugin = { module = "io.github.gradle-nexus:publish-plugin", version.ref = "nexus-plugin-version" }
smithy-model = { module = "software.amazon.smithy:smithy-model", version.ref = "smithy-version" }
smithy-gradle-base-plugin = { module = "software.amazon.smithy.gradle:smithy-base", version.ref = "smithy-gradle-plugin-version" }

Expand Down
Loading