55package aws.sdk.kotlin.gradle.dsl
66
77import aws.sdk.kotlin.gradle.util.verifyRootProject
8+ import io.github.gradlenexus.publishplugin.NexusPublishExtension
89import org.gradle.api.Project
910import org.gradle.api.publish.PublishingExtension
1011import org.gradle.api.publish.maven.MavenPublication
@@ -15,9 +16,17 @@ import org.gradle.plugins.signing.Sign
1516import org.gradle.plugins.signing.SigningExtension
1617import org.jreleaser.gradle.plugin.JReleaserExtension
1718import org.jreleaser.model.Active
19+ import java.time.Duration
1820
1921private object Properties {
2022 const val SKIP_PUBLISHING = " skipPublish"
23+
24+ // Nexus publish plugin properties
25+ const val PUBLISH_GROUP_NAME_PROP = " publishGroupName"
26+ const val SIGNING_KEY_PROP = " signingKey"
27+ const val SIGNING_PASSWORD_PROP = " signingPassword"
28+ const val SONATYPE_USERNAME_PROP = " sonatypeUsername"
29+ const val SONATYPE_PASSWORD_PROP = " sonatypePassword"
2130}
2231
2332private object EnvironmentVariables {
@@ -61,7 +70,11 @@ fun Project.skipPublishing() {
6170 * @param repoName the repository name (e.g. `smithy-kotlin`, `aws-sdk-kotlin`, etc)
6271 * @param githubOrganization the name of the GitHub organization that [repoName] is located in
6372 */
64- fun Project.configurePublishing (repoName : String , githubOrganization : String = "awslabs") {
73+ fun Project.configurePublishing (
74+ repoName : String ,
75+ githubOrganization : String = "awslabs",
76+ useNexusPublishPlugin : Boolean = false, // TODO:
77+ ) {
6578 val project = this
6679 apply (plugin = " maven-publish" )
6780
@@ -111,8 +124,17 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = "
111124 }
112125 }
113126
114- val secretKey = System .getenv(EnvironmentVariables .GPG_SECRET_KEY )
115- val passphrase = System .getenv(EnvironmentVariables .GPG_PASSPHRASE )
127+ val secretKey = if (useNexusPublishPlugin) {
128+ project.property(Properties .SIGNING_KEY_PROP ) as String
129+ } else {
130+ System .getenv(EnvironmentVariables .GPG_SECRET_KEY )
131+ }
132+
133+ val passphrase = if (useNexusPublishPlugin) {
134+ project.property(Properties .SIGNING_PASSWORD_PROP ) as String
135+ } else {
136+ System .getenv(EnvironmentVariables .GPG_PASSPHRASE )
137+ }
116138
117139 if (! secretKey.isNullOrBlank() && ! passphrase.isNullOrBlank()) {
118140 apply (plugin = " signing" )
@@ -218,6 +240,46 @@ fun Project.configureJReleaser() {
218240 }
219241}
220242
243+ /* *
244+ * Configure nexus publishing plugin. This (conditionally) enables the `gradle-nexus.publish-plugin` and configures it.
245+ */
246+ fun Project.configureNexus (
247+ nexusUrl : String = "https : // ossrh-staging-api.central.sonatype.com/service/local/",
248+ snapshotRepositoryUrl : String = "https : // central.sonatype.com/repository/maven-snapshots/",
249+ ) {
250+ verifyRootProject { " Kotlin SDK nexus configuration must be applied to the root project only" }
251+
252+ val requiredProps = listOf (
253+ Properties .SONATYPE_USERNAME_PROP ,
254+ Properties .SONATYPE_PASSWORD_PROP ,
255+ Properties .PUBLISH_GROUP_NAME_PROP ,
256+ )
257+ val doConfigure = requiredProps.all { project.hasProperty(it) }
258+ if (! doConfigure) {
259+ logger.info(" skipping nexus configuration, missing one or more required properties: $requiredProps " )
260+ return
261+ }
262+
263+ apply (plugin = " io.github.gradle-nexus.publish-plugin" )
264+ extensions.configure<NexusPublishExtension > {
265+ val publishGroupName = project.property(Properties .PUBLISH_GROUP_NAME_PROP ) as String
266+ group = publishGroupName
267+ packageGroup.set(publishGroupName)
268+ repositories {
269+ create(" awsNexus" ) {
270+ this .nexusUrl.set(uri(nexusUrl))
271+ this .snapshotRepositoryUrl.set(uri(snapshotRepositoryUrl))
272+ username.set(project.property(Properties .SONATYPE_USERNAME_PROP ) as String )
273+ password.set(project.property(Properties .SONATYPE_PASSWORD_PROP ) as String )
274+ }
275+ }
276+
277+ transitionCheckOptions {
278+ maxRetries.set(180 )
279+ delayBetween.set(Duration .ofSeconds(10 ))
280+ }
281+ }
282+ }
221283private fun isAvailableForPublication (project : Project , publication : MavenPublication ): Boolean {
222284 var shouldPublish = true
223285
0 commit comments