generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 2
misc: migrate to jreleaser #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2d41f84
feat: migrate from publish-plugin to jreleaser
0marperez 0c2c5f0
checkpoint
0marperez ca18ac0
pull from main
0marperez 5d26543
finalize
0marperez 9ff14c4
pull from origin
0marperez 01cd410
checkpoint
0marperez 0a15435
misc: clean up and system properties
0marperez 1600747
misc: self review
0marperez ba0cc48
properties to env vars
0marperez 87d5f4d
self review
0marperez d48fce5
misc: configure version catalog in jreleaser
0marperez a42d596
review feedback
0marperez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,6 @@ | |
| 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 | ||
|
|
@@ -14,17 +13,25 @@ import org.gradle.api.tasks.bundling.Jar | |
| import org.gradle.kotlin.dsl.* | ||
| import org.gradle.plugins.signing.Sign | ||
| import org.gradle.plugins.signing.SigningExtension | ||
| import java.time.Duration | ||
| import org.jreleaser.gradle.plugin.JReleaserExtension | ||
| import org.jreleaser.model.Active | ||
|
|
||
| private const val PUBLISH_GROUP_NAME_PROP = "publishGroupName" | ||
| private const val SKIP_PUBLISH_PROP = "skipPublish" | ||
| 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 Properties { | ||
| const val SKIP_PUBLISHING = "skipPublish" | ||
| } | ||
|
|
||
| // Names of publications that are allowed to be published | ||
| private val ALLOWED_PUBLICATIONS = listOf( | ||
| private object EnvironmentVariables { | ||
| object JReleaser { | ||
| const val GROUP_ID = "JRELEASER_PROJECT_JAVA_GROUP_ID" | ||
| const val MAVEN_CENTRAL_USERNAME = "JRELEASER_MAVENCENTRAL_USERNAME" | ||
| const val MAVEN_CENTRAL_TOKEN = "JRELEASER_MAVENCENTRAL_TOKEN" | ||
| const val GPG_PASSPHRASE = "JRELEASER_GPG_PASSPHRASE" | ||
| const val GPG_PUBLIC_KEY = "JRELEASER_GPG_PUBLIC_KEY" | ||
| const val GPG_SECRET_KEY = "JRELEASER_GPG_SECRET_KEY" | ||
| } | ||
| } | ||
|
|
||
| private val ALLOWED_PUBLICATION_NAMES = setOf( | ||
| "common", | ||
| "jvm", | ||
| "metadata", | ||
|
|
@@ -47,7 +54,7 @@ private val ALLOWED_PUBLICATIONS = listOf( | |
| * Mark this project as excluded from publishing | ||
| */ | ||
| fun Project.skipPublishing() { | ||
| extra.set(SKIP_PUBLISH_PROP, true) | ||
| extra.set(Properties.SKIP_PUBLISHING, true) | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -106,12 +113,15 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = " | |
| } | ||
| } | ||
|
|
||
| if (project.hasProperty(SIGNING_KEY_PROP) && project.hasProperty(SIGNING_PASSWORD_PROP)) { | ||
| val secretKey = System.getenv(EnvironmentVariables.JReleaser.GPG_SECRET_KEY) | ||
| val passphrase = System.getenv(EnvironmentVariables.JReleaser.GPG_PASSPHRASE) | ||
|
|
||
| if (!secretKey.isNullOrBlank() && !passphrase.isNullOrBlank()) { | ||
| apply(plugin = "signing") | ||
| extensions.configure<SigningExtension> { | ||
| useInMemoryPgpKeys( | ||
| project.property(SIGNING_KEY_PROP) as String, | ||
| project.property(SIGNING_PASSWORD_PROP) as String, | ||
| secretKey, | ||
| passphrase, | ||
| ) | ||
| sign(publications) | ||
| } | ||
|
|
@@ -133,41 +143,61 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = " | |
| } | ||
| } | ||
| } | ||
|
|
||
| /* | ||
| Creates a placeholder JAR for the version catalog | ||
| The `version-catalog` plugin doesn't generate one because it isn't needed but JReleaser requires a jar | ||
| https://docs.gradle.org/current/userguide/version_catalogs.html#sec:version-catalog-plugin | ||
| */ | ||
| tasks.register<Jar>("versionCatalogJar") { | ||
| archiveBaseName.set("version-catalog") | ||
| from("gradle/libs.versions.toml") | ||
| } | ||
|
||
| } | ||
|
|
||
| /** | ||
| * Configure nexus publishing plugin. This (conditionally) enables the `gradle-nexus.publish-plugin` and configures it. | ||
| * Configure JReleaser publishing plugin. This (conditionally) enables the `org.jreleaser` 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 | ||
| fun Project.configureJReleaser() { | ||
| verifyRootProject { "JReleaser configuration must be applied to the root project only" } | ||
|
|
||
| var missingVariables = false | ||
| listOf( | ||
| EnvironmentVariables.JReleaser.MAVEN_CENTRAL_USERNAME, | ||
| EnvironmentVariables.JReleaser.MAVEN_CENTRAL_TOKEN, | ||
| EnvironmentVariables.JReleaser.GPG_PASSPHRASE, | ||
| EnvironmentVariables.JReleaser.GPG_PUBLIC_KEY, | ||
| EnvironmentVariables.JReleaser.GPG_SECRET_KEY, | ||
| ).forEach { | ||
| if (System.getenv(it).isNullOrBlank()) { | ||
| missingVariables = true | ||
| logger.warn("Skipping JReleaser configuration, missing required environment variable: $it") | ||
| } | ||
| } | ||
| if (missingVariables) 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) | ||
| } | ||
| } | ||
| // Get SDK version from gradle.properties | ||
| val sdkVersion: String by project | ||
|
|
||
| transitionCheckOptions { | ||
| maxRetries.set(180) | ||
| delayBetween.set(Duration.ofSeconds(10)) | ||
| apply(plugin = "org.jreleaser") | ||
| extensions.configure<JReleaserExtension> { | ||
| project { | ||
| version = sdkVersion | ||
| } | ||
| signing { | ||
| active = Active.ALWAYS | ||
| armored = true | ||
| } | ||
| deploy { | ||
| maven { | ||
| mavenCentral { | ||
| create("maven-central") { | ||
| active = Active.ALWAYS | ||
| url = "https://central.sonatype.com/api/v1/publisher" | ||
| stagingRepository(rootProject.layout.buildDirectory.dir("m2").get().toString()) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -176,14 +206,14 @@ private fun isAvailableForPublication(project: Project, publication: MavenPublic | |
| var shouldPublish = true | ||
|
|
||
| // Check SKIP_PUBLISH_PROP | ||
| if (project.extra.has(SKIP_PUBLISH_PROP)) shouldPublish = false | ||
| if (project.extra.has(Properties.SKIP_PUBLISHING)) shouldPublish = false | ||
|
|
||
| // Validate publishGroupName | ||
| val publishGroupName = project.findProperty(PUBLISH_GROUP_NAME_PROP) as? String | ||
| // Only publish publications with the configured group from JReleaser or everything if JReleaser group is not configured | ||
| val publishGroupName = System.getenv(EnvironmentVariables.JReleaser.GROUP_ID) | ||
| shouldPublish = shouldPublish && (publishGroupName == null || publication.groupId.startsWith(publishGroupName)) | ||
|
|
||
| // Validate publication name is allowed to be published | ||
| shouldPublish = shouldPublish && ALLOWED_PUBLICATIONS.any { publication.name.equals(it, ignoreCase = true) } | ||
| shouldPublish = shouldPublish && ALLOWED_PUBLICATION_NAMES.any { publication.name.equals(it, ignoreCase = true) } | ||
|
|
||
| return shouldPublish | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Isn't everything in this file already specific to JReleaser? Seems like we could just remove the
object JReleaserwrapper and keep the env vars inside the top-level object like we did with properties.