Skip to content
Merged
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
3 changes: 2 additions & 1 deletion build-plugins/build-support/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ dependencies {
exclude(group = "org.jetbrains.kotlin", module = "kotlin-compiler-embeddable")
}

implementation(libs.jReleaserPlugin)
implementation(libs.nexus.publish.plugin)
implementation(libs.jreleaser.plugin)
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,11 +16,19 @@ 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"
}

// TODO Remove once aws-sdk-kotlin migrates to Central Portal
private const val PUBLISH_GROUP_NAME_PROP = "publishGroupName"
private const val SIGNING_KEY_PROP = "signingKey"
private const val SIGNING_PASSWORD_PROP = "signingPassword"
private const val SONATYPE_USERNAME_PROP = "sonatypeUsername"
private const val SONATYPE_PASSWORD_PROP = "sonatypePassword"

private object EnvironmentVariables {
const val GROUP_ID = "JRELEASER_PROJECT_JAVA_GROUP_ID"
const val MAVEN_CENTRAL_USERNAME = "JRELEASER_MAVENCENTRAL_USERNAME"
Expand Down Expand Up @@ -55,6 +64,102 @@ fun Project.skipPublishing() {
extra.set(Properties.SKIP_PUBLISHING, true)
}

// TODO Remove this once aws-sdk-kotlin migrates to Central Portal
fun Project.configureNexusPublishing(repoName: String, githubOrganization: String = "awslabs") {
val project = this
apply(plugin = "maven-publish")

// FIXME: create a real "javadoc" JAR from Dokka output
val javadocJar = tasks.register<Jar>("emptyJar") {
archiveClassifier.set("javadoc")
destinationDirectory.set(layout.buildDirectory.dir("libs"))
from()
}

extensions.configure<PublishingExtension> {
repositories {
maven {
name = "testLocal"
url = rootProject.layout.buildDirectory.dir("m2").get().asFile.toURI()
}
}

publications.all {
if (this !is MavenPublication) return@all

project.afterEvaluate {
pom {
name.set(project.name)
description.set(project.description)
url.set("https://github.com/$githubOrganization/$repoName")
licenses {
license {
name.set("Apache-2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set(repoName)
name.set("AWS SDK Kotlin Team")
}
}
scm {
connection.set("scm:git:git://github.com/$githubOrganization/$repoName.git")
developerConnection.set("scm:git:ssh://github.com/$githubOrganization/$repoName.git")
url.set("https://github.com/$githubOrganization/$repoName")
}

artifact(javadocJar)
}
}
}

if (project.hasProperty(SIGNING_KEY_PROP) && project.hasProperty(SIGNING_PASSWORD_PROP)) {
apply(plugin = "signing")
extensions.configure<SigningExtension> {
useInMemoryPgpKeys(
project.property(SIGNING_KEY_PROP) as String,
project.property(SIGNING_PASSWORD_PROP) as String,
)
sign(publications)
}

// FIXME - workaround for https://github.com/gradle/gradle/issues/26091
val signingTasks = tasks.withType<Sign>()
tasks.withType<AbstractPublishToMaven>().configureEach {
mustRunAfter(signingTasks)
}
}
}

fun isAvailableForNexusPublication(project: Project, publication: MavenPublication): Boolean {
var shouldPublish = true

// Check SKIP_PUBLISH_PROP
if (project.extra.has(Properties.SKIP_PUBLISHING)) shouldPublish = false

// Only publish publications with the configured group from JReleaser or everything if JReleaser group is not configured
val publishGroupName = project.findProperty(PUBLISH_GROUP_NAME_PROP) as? String
shouldPublish = shouldPublish && (publishGroupName == null || publication.groupId.startsWith(publishGroupName))

// Validate publication name is allowed to be published
shouldPublish = shouldPublish && ALLOWED_PUBLICATION_NAMES.any { publication.name.equals(it, ignoreCase = true) }

return shouldPublish
}

tasks.withType<AbstractPublishToMaven>().configureEach {
onlyIf {
isAvailableForNexusPublication(project, publication).also {
if (!it) {
logger.warn("Skipping publication, project=${project.name}; publication=${publication.name}; group=${publication.groupId}")
}
}
}
}
}

/**
* Configure publishing for this project. This applies the `maven-publish` and `signing` plugins and configures
* the publications.
Expand Down Expand Up @@ -143,6 +248,43 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = "
}
}

/**
* 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(SONATYPE_USERNAME_PROP, SONATYPE_PASSWORD_PROP, 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(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(SONATYPE_USERNAME_PROP) as String)
password.set(project.property(SONATYPE_PASSWORD_PROP) as String)
}
}

transitionCheckOptions {
maxRetries.set(180)
delayBetween.set(Duration.ofSeconds(10))
}
}
}

/**
* Configure JReleaser publishing plugin. This (conditionally) enables the `org.jreleaser` plugin and configures it.
*/
Expand Down
5 changes: 5 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ if (releaseVersion == null) logger.warn("no release version set")
val s3Url = propertyOrEnv("release.s3.url", "RELEASE_S3_URL")
if (s3Url == null) logger.warn("S3 repository not configured, missing S3 url")

allprojects {
// Enables running `./gradlew allDeps` to get a comprehensive list of dependencies for every subproject
tasks.register<DependencyReportTask>("allDeps") { }
}

subprojects {
group = "aws.sdk.kotlin.gradle"
version = releaseVersion ?: "0.0.1"
Expand Down
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
aws-sdk-version = "1.4.116"
kotlin-version = "2.2.0"
ktlint = "1.3.0"
nexus-plugin-version = "2.0.0"
jreleaser-plugin-version = "1.18.0"
publish-plugin-version = "1.3.1"
smithy-version = "1.60.2"
Expand All @@ -14,7 +15,8 @@ aws-sdk-s3 = { module = "aws.sdk.kotlin:s3", version.ref = "aws-sdk-version" }
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" }
nexus-publish-plugin = { module = "io.github.gradle-nexus:publish-plugin", version.ref = "nexus-plugin-version" }
jreleaser-plugin = { module = "org.jreleaser:jreleaser-gradle-plugin", version.ref = "jreleaser-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