55package aws.sdk.kotlin.gradle.dsl
66
77import aws.sdk.kotlin.gradle.util.verifyRootProject
8- import io.github.gradlenexus.publishplugin.NexusPublishExtension
98import org.gradle.api.Project
109import org.gradle.api.publish.PublishingExtension
1110import org.gradle.api.publish.maven.MavenPublication
@@ -14,17 +13,23 @@ import org.gradle.api.tasks.bundling.Jar
1413import org.gradle.kotlin.dsl.*
1514import org.gradle.plugins.signing.Sign
1615import 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 */
4954fun 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}
0 commit comments