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 " kotlinMultiplatform" ,
@@ -53,7 +58,7 @@ private val ALLOWED_PUBLICATIONS = listOf(
5358 * Mark this project as excluded from publishing
5459 */
5560fun Project.skipPublishing () {
56- extra.set(SKIP_PUBLISH_PROP , true )
61+ extra.set(Properties . SKIP_PUBLISHING , true )
5762}
5863
5964/* *
@@ -112,12 +117,15 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = "
112117 }
113118 }
114119
115- if (project.hasProperty(SIGNING_KEY_PROP ) && project.hasProperty(SIGNING_PASSWORD_PROP )) {
120+ val secretKey = System .getenv(EnvironmentVariables .GPG_SECRET_KEY )
121+ val passphrase = System .getenv(EnvironmentVariables .GPG_PASSPHRASE )
122+
123+ if (! secretKey.isNullOrBlank() && ! passphrase.isNullOrBlank()) {
116124 apply (plugin = " signing" )
117125 extensions.configure<SigningExtension > {
118126 useInMemoryPgpKeys(
119- project.property( SIGNING_KEY_PROP ) as String ,
120- project.property( SIGNING_PASSWORD_PROP ) as String ,
127+ secretKey ,
128+ passphrase ,
121129 )
122130 sign(publications)
123131 }
@@ -142,38 +150,55 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = "
142150}
143151
144152/* *
145- * Configure nexus publishing plugin. This (conditionally) enables the `gradle-nexus.publish-plugin` and configures it.
153+ * Configure JReleaser publishing plugin. This (conditionally) enables the `org.jreleaser` plugin and configures it.
146154 */
147- fun Project.configureNexus (
148- nexusUrl : String = "https : // ossrh-staging-api.central.sonatype.com/service/local/",
149- snapshotRepositoryUrl : String = "https : // central.sonatype.com/repository/maven-snapshots/",
150- ) {
151- verifyRootProject { " Kotlin SDK nexus configuration must be applied to the root project only" }
152-
153- val requiredProps = listOf (SONATYPE_USERNAME_PROP , SONATYPE_PASSWORD_PROP , PUBLISH_GROUP_NAME_PROP )
154- val doConfigure = requiredProps.all { project.hasProperty(it) }
155- if (! doConfigure) {
156- logger.info(" skipping nexus configuration, missing one or more required properties: $requiredProps " )
157- return
155+ fun Project.configureJReleaser () {
156+ verifyRootProject { " JReleaser configuration must be applied to the root project only" }
157+
158+ var missingVariables = false
159+ listOf (
160+ EnvironmentVariables .MAVEN_CENTRAL_USERNAME ,
161+ EnvironmentVariables .MAVEN_CENTRAL_TOKEN ,
162+ EnvironmentVariables .GPG_PASSPHRASE ,
163+ EnvironmentVariables .GPG_PUBLIC_KEY ,
164+ EnvironmentVariables .GPG_SECRET_KEY ,
165+ ).forEach {
166+ if (System .getenv(it).isNullOrBlank()) {
167+ missingVariables = true
168+ logger.warn(" Skipping JReleaser configuration, missing required environment variable: $it " )
169+ }
158170 }
171+ if (missingVariables) return
159172
160- apply (plugin = " io.github.gradle-nexus.publish-plugin" )
161- extensions.configure<NexusPublishExtension > {
162- val publishGroupName = project.property(PUBLISH_GROUP_NAME_PROP ) as String
163- group = publishGroupName
164- packageGroup.set(publishGroupName)
165- repositories {
166- create(" awsNexus" ) {
167- this .nexusUrl.set(uri(nexusUrl))
168- this .snapshotRepositoryUrl.set(uri(snapshotRepositoryUrl))
169- username.set(project.property(SONATYPE_USERNAME_PROP ) as String )
170- password.set(project.property(SONATYPE_PASSWORD_PROP ) as String )
171- }
172- }
173+ // Get SDK version from gradle.properties
174+ val sdkVersion: String by project
173175
174- transitionCheckOptions {
175- maxRetries.set(180 )
176- delayBetween.set(Duration .ofSeconds(10 ))
176+ apply (plugin = " org.jreleaser" )
177+ extensions.configure<JReleaserExtension > {
178+ project {
179+ version = sdkVersion
180+ }
181+ signing {
182+ active = Active .ALWAYS
183+ armored = true
184+ }
185+ deploy {
186+ maven {
187+ mavenCentral {
188+ create(" maven-central" ) {
189+ active = Active .ALWAYS
190+ url = " https://central.sonatype.com/api/v1/publisher"
191+ stagingRepository(rootProject.layout.buildDirectory.dir(" m2" ).get().toString())
192+ artifacts {
193+ artifactOverride {
194+ artifactId = " version-catalog"
195+ jar = false
196+ verifyPom = false // jreleaser doesn't understand toml packaging
197+ }
198+ }
199+ }
200+ }
201+ }
177202 }
178203 }
179204}
@@ -182,14 +207,14 @@ private fun isAvailableForPublication(project: Project, publication: MavenPublic
182207 var shouldPublish = true
183208
184209 // Check SKIP_PUBLISH_PROP
185- if (project.extra.has(SKIP_PUBLISH_PROP )) shouldPublish = false
210+ if (project.extra.has(Properties . SKIP_PUBLISHING )) shouldPublish = false
186211
187- // Validate publishGroupName
188- val publishGroupName = project.findProperty( PUBLISH_GROUP_NAME_PROP ) as ? String
212+ // Only publish publications with the configured group from JReleaser or everything if JReleaser group is not configured
213+ val publishGroupName = System .getenv( EnvironmentVariables . GROUP_ID )
189214 shouldPublish = shouldPublish && (publishGroupName == null || publication.groupId.startsWith(publishGroupName))
190215
191216 // Validate publication name is allowed to be published
192- shouldPublish = shouldPublish && ALLOWED_PUBLICATIONS .any { publication.name.equals(it, ignoreCase = true ) }
217+ shouldPublish = shouldPublish && ALLOWED_PUBLICATION_NAMES .any { publication.name.equals(it, ignoreCase = true ) }
193218
194219 return shouldPublish
195220}
0 commit comments