Skip to content

Commit 6ec8cda

Browse files
authored
misc: migrate to jreleaser (#102)
1 parent 85c4f79 commit 6ec8cda

File tree

3 files changed

+74
-49
lines changed

3 files changed

+74
-49
lines changed

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

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

27-
implementation(libs.nexusPublishPlugin)
27+
implementation(libs.jReleaserPlugin)
2828
compileOnly(gradleApi())
2929
implementation(libs.aws.sdk.s3)
3030
implementation(libs.aws.sdk.cloudwatch)

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

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

77
import aws.sdk.kotlin.gradle.util.verifyRootProject
8-
import io.github.gradlenexus.publishplugin.NexusPublishExtension
98
import org.gradle.api.Project
109
import org.gradle.api.publish.PublishingExtension
1110
import org.gradle.api.publish.maven.MavenPublication
@@ -14,17 +13,23 @@ import org.gradle.api.tasks.bundling.Jar
1413
import org.gradle.kotlin.dsl.*
1514
import org.gradle.plugins.signing.Sign
1615
import org.gradle.plugins.signing.SigningExtension
17-
import java.time.Duration
16+
import org.jreleaser.gradle.plugin.JReleaserExtension
17+
import org.jreleaser.model.Active
1818

19-
private const val PUBLISH_GROUP_NAME_PROP = "publishGroupName"
20-
private const val SKIP_PUBLISH_PROP = "skipPublish"
21-
private const val SIGNING_KEY_PROP = "signingKey"
22-
private const val SIGNING_PASSWORD_PROP = "signingPassword"
23-
private const val SONATYPE_USERNAME_PROP = "sonatypeUsername"
24-
private const val SONATYPE_PASSWORD_PROP = "sonatypePassword"
19+
private object Properties {
20+
const val SKIP_PUBLISHING = "skipPublish"
21+
}
22+
23+
private object EnvironmentVariables {
24+
const val GROUP_ID = "JRELEASER_PROJECT_JAVA_GROUP_ID"
25+
const val MAVEN_CENTRAL_USERNAME = "JRELEASER_MAVENCENTRAL_USERNAME"
26+
const val MAVEN_CENTRAL_TOKEN = "JRELEASER_MAVENCENTRAL_TOKEN"
27+
const val GPG_PASSPHRASE = "JRELEASER_GPG_PASSPHRASE"
28+
const val GPG_PUBLIC_KEY = "JRELEASER_GPG_PUBLIC_KEY"
29+
const val GPG_SECRET_KEY = "JRELEASER_GPG_SECRET_KEY"
30+
}
2531

26-
// Names of publications that are allowed to be published
27-
private val ALLOWED_PUBLICATIONS = listOf(
32+
private val ALLOWED_PUBLICATION_NAMES = setOf(
2833
"common",
2934
"jvm",
3035
"metadata",
@@ -47,7 +52,7 @@ private val ALLOWED_PUBLICATIONS = listOf(
4752
* Mark this project as excluded from publishing
4853
*/
4954
fun Project.skipPublishing() {
50-
extra.set(SKIP_PUBLISH_PROP, true)
55+
extra.set(Properties.SKIP_PUBLISHING, true)
5156
}
5257

5358
/**
@@ -106,12 +111,15 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = "
106111
}
107112
}
108113

109-
if (project.hasProperty(SIGNING_KEY_PROP) && project.hasProperty(SIGNING_PASSWORD_PROP)) {
114+
val secretKey = System.getenv(EnvironmentVariables.GPG_SECRET_KEY)
115+
val passphrase = System.getenv(EnvironmentVariables.GPG_PASSPHRASE)
116+
117+
if (!secretKey.isNullOrBlank() && !passphrase.isNullOrBlank()) {
110118
apply(plugin = "signing")
111119
extensions.configure<SigningExtension> {
112120
useInMemoryPgpKeys(
113-
project.property(SIGNING_KEY_PROP) as String,
114-
project.property(SIGNING_PASSWORD_PROP) as String,
121+
secretKey,
122+
passphrase,
115123
)
116124
sign(publications)
117125
}
@@ -136,38 +144,55 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = "
136144
}
137145

138146
/**
139-
* Configure nexus publishing plugin. This (conditionally) enables the `gradle-nexus.publish-plugin` and configures it.
147+
* Configure JReleaser publishing plugin. This (conditionally) enables the `org.jreleaser` plugin and configures it.
140148
*/
141-
fun Project.configureNexus(
142-
nexusUrl: String = "https://ossrh-staging-api.central.sonatype.com/service/local/",
143-
snapshotRepositoryUrl: String = "https://central.sonatype.com/repository/maven-snapshots/",
144-
) {
145-
verifyRootProject { "Kotlin SDK nexus configuration must be applied to the root project only" }
146-
147-
val requiredProps = listOf(SONATYPE_USERNAME_PROP, SONATYPE_PASSWORD_PROP, PUBLISH_GROUP_NAME_PROP)
148-
val doConfigure = requiredProps.all { project.hasProperty(it) }
149-
if (!doConfigure) {
150-
logger.info("skipping nexus configuration, missing one or more required properties: $requiredProps")
151-
return
149+
fun Project.configureJReleaser() {
150+
verifyRootProject { "JReleaser configuration must be applied to the root project only" }
151+
152+
var missingVariables = false
153+
listOf(
154+
EnvironmentVariables.MAVEN_CENTRAL_USERNAME,
155+
EnvironmentVariables.MAVEN_CENTRAL_TOKEN,
156+
EnvironmentVariables.GPG_PASSPHRASE,
157+
EnvironmentVariables.GPG_PUBLIC_KEY,
158+
EnvironmentVariables.GPG_SECRET_KEY,
159+
).forEach {
160+
if (System.getenv(it).isNullOrBlank()) {
161+
missingVariables = true
162+
logger.warn("Skipping JReleaser configuration, missing required environment variable: $it")
163+
}
152164
}
165+
if (missingVariables) return
153166

154-
apply(plugin = "io.github.gradle-nexus.publish-plugin")
155-
extensions.configure<NexusPublishExtension> {
156-
val publishGroupName = project.property(PUBLISH_GROUP_NAME_PROP) as String
157-
group = publishGroupName
158-
packageGroup.set(publishGroupName)
159-
repositories {
160-
create("awsNexus") {
161-
this.nexusUrl.set(uri(nexusUrl))
162-
this.snapshotRepositoryUrl.set(uri(snapshotRepositoryUrl))
163-
username.set(project.property(SONATYPE_USERNAME_PROP) as String)
164-
password.set(project.property(SONATYPE_PASSWORD_PROP) as String)
165-
}
166-
}
167+
// Get SDK version from gradle.properties
168+
val sdkVersion: String by project
167169

168-
transitionCheckOptions {
169-
maxRetries.set(180)
170-
delayBetween.set(Duration.ofSeconds(10))
170+
apply(plugin = "org.jreleaser")
171+
extensions.configure<JReleaserExtension> {
172+
project {
173+
version = sdkVersion
174+
}
175+
signing {
176+
active = Active.ALWAYS
177+
armored = true
178+
}
179+
deploy {
180+
maven {
181+
mavenCentral {
182+
create("maven-central") {
183+
active = Active.ALWAYS
184+
url = "https://central.sonatype.com/api/v1/publisher"
185+
stagingRepository(rootProject.layout.buildDirectory.dir("m2").get().toString())
186+
artifacts {
187+
artifactOverride {
188+
artifactId = "version-catalog"
189+
jar = false
190+
verifyPom = false // jreleaser doesn't understand toml packaging
191+
}
192+
}
193+
}
194+
}
195+
}
171196
}
172197
}
173198
}
@@ -176,14 +201,14 @@ private fun isAvailableForPublication(project: Project, publication: MavenPublic
176201
var shouldPublish = true
177202

178203
// Check SKIP_PUBLISH_PROP
179-
if (project.extra.has(SKIP_PUBLISH_PROP)) shouldPublish = false
204+
if (project.extra.has(Properties.SKIP_PUBLISHING)) shouldPublish = false
180205

181-
// Validate publishGroupName
182-
val publishGroupName = project.findProperty(PUBLISH_GROUP_NAME_PROP) as? String
206+
// Only publish publications with the configured group from JReleaser or everything if JReleaser group is not configured
207+
val publishGroupName = System.getenv(EnvironmentVariables.GROUP_ID)
183208
shouldPublish = shouldPublish && (publishGroupName == null || publication.groupId.startsWith(publishGroupName))
184209

185210
// Validate publication name is allowed to be published
186-
shouldPublish = shouldPublish && ALLOWED_PUBLICATIONS.any { publication.name.equals(it, ignoreCase = true) }
211+
shouldPublish = shouldPublish && ALLOWED_PUBLICATION_NAMES.any { publication.name.equals(it, ignoreCase = true) }
187212

188213
return shouldPublish
189214
}

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +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"
5+
jreleaser-plugin-version = "1.18.0"
66
publish-plugin-version = "1.3.1"
77
smithy-version = "1.60.2"
88
smithy-gradle-plugin-version = "1.3.0"
@@ -14,7 +14,7 @@ aws-sdk-s3 = { module = "aws.sdk.kotlin:s3", version.ref = "aws-sdk-version" }
1414
ktlint-cli = { module = "com.pinterest.ktlint:ktlint-cli", version.ref = "ktlint" }
1515
ktlint-cli-ruleset-core = { module = "com.pinterest.ktlint:ktlint-cli-ruleset-core", version.ref = "ktlint" }
1616
ktlint-test = {module = "com.pinterest.ktlint:ktlint-test", version.ref = "ktlint" }
17-
nexusPublishPlugin = { module = "io.github.gradle-nexus:publish-plugin", version.ref = "nexus-plugin-version" }
17+
jReleaserPlugin = { module = "org.jreleaser:jreleaser-gradle-plugin", version.ref = "jreleaser-plugin-version" }
1818
smithy-model = { module = "software.amazon.smithy:smithy-model", version.ref = "smithy-version" }
1919
smithy-gradle-base-plugin = { module = "software.amazon.smithy.gradle:smithy-base", version.ref = "smithy-gradle-plugin-version" }
2020

0 commit comments

Comments
 (0)