55package aws.sdk.kotlin.gradle.dsl
66
77import aws.sdk.kotlin.gradle.util.getOrNull
8- import aws.sdk.kotlin.gradle.util.verifyRootProject
9- import io.github.gradlenexus.publishplugin.NexusPublishExtension
108import org.gradle.api.Project
119import org.gradle.api.publish.PublishingExtension
1210import org.gradle.api.publish.maven.MavenPublication
@@ -15,34 +13,13 @@ import org.gradle.api.tasks.bundling.Jar
1513import org.gradle.kotlin.dsl.*
1614import org.gradle.plugins.signing.Sign
1715import org.gradle.plugins.signing.SigningExtension
18- import org.jreleaser.gradle.plugin.JReleaserExtension
19- import org.jreleaser.model.Active
20- import java.time.Duration
2116
2217// FIXME Relocate this file to `aws.sdk.kotlin.gradle.publishing`
2318
2419private object Properties {
2520 const val SKIP_PUBLISHING = " skipPublish"
2621}
2722
28- // TODO Remove once aws-sdk-kotlin migrates to Central Portal
29- private const val PUBLISH_GROUP_NAME_PROP = " publishGroupName"
30- private const val SIGNING_KEY_PROP = " signingKey"
31- private const val SIGNING_PASSWORD_PROP = " signingPassword"
32- private const val SONATYPE_USERNAME_PROP = " sonatypeUsername"
33- private const val SONATYPE_PASSWORD_PROP = " sonatypePassword"
34-
35- // TODO Remove JReleaser environment variables when smithy-kotlin + aws-crt-kotlin are migrated to custom Sonatype integration
36- private object EnvironmentVariables {
37- const val GROUP_ID = " JRELEASER_PROJECT_JAVA_GROUP_ID"
38- const val MAVEN_CENTRAL_USERNAME = " JRELEASER_MAVENCENTRAL_USERNAME"
39- const val MAVEN_CENTRAL_TOKEN = " JRELEASER_MAVENCENTRAL_TOKEN"
40- const val GPG_PASSPHRASE = " JRELEASER_GPG_PASSPHRASE"
41- const val GPG_PUBLIC_KEY = " JRELEASER_GPG_PUBLIC_KEY"
42- const val GPG_SECRET_KEY = " JRELEASER_GPG_SECRET_KEY"
43- const val GENERIC_TOKEN = " JRELEASER_GENERIC_TOKEN"
44- }
45-
4623private const val SIGNING_PUBLIC_KEY = " SIGNING_KEY"
4724private const val SIGNING_SECRET_KEY = " SIGNING_PASSWORD"
4825
@@ -80,6 +57,7 @@ private val ALLOWED_KOTLIN_NATIVE_GROUP_NAMES = setOf(
8057 " aws.sdk.kotlin.crt" ,
8158 " aws.smithy.kotlin" ,
8259 " com.sonatype.central.testing.amazon" ,
60+ " aws.sdk.kotlin" ,
8361)
8462
8563// Optional override to the above set.
@@ -93,102 +71,6 @@ fun Project.skipPublishing() {
9371 extra.set(Properties .SKIP_PUBLISHING , true )
9472}
9573
96- // TODO Remove this once aws-sdk-kotlin migrates to Central Portal
97- fun Project.configureNexusPublishing (repoName : String , githubOrganization : String = "aws") {
98- val project = this
99- apply (plugin = " maven-publish" )
100-
101- // FIXME: create a real "javadoc" JAR from Dokka output
102- val javadocJar = tasks.register<Jar >(" emptyJar" ) {
103- archiveClassifier.set(" javadoc" )
104- destinationDirectory.set(layout.buildDirectory.dir(" libs" ))
105- from()
106- }
107-
108- extensions.configure<PublishingExtension > {
109- repositories {
110- maven {
111- name = " testLocal"
112- url = rootProject.layout.buildDirectory.dir(" m2" ).get().asFile.toURI()
113- }
114- }
115-
116- publications.all {
117- if (this !is MavenPublication ) return @all
118-
119- project.afterEvaluate {
120- pom {
121- name.set(project.name)
122- description.set(project.description)
123- url.set(" https://github.com/$githubOrganization /$repoName " )
124- licenses {
125- license {
126- name.set(" Apache-2.0" )
127- url.set(" https://www.apache.org/licenses/LICENSE-2.0.txt" )
128- }
129- }
130- developers {
131- developer {
132- id.set(repoName)
133- name.set(" AWS SDK Kotlin Team" )
134- }
135- }
136- scm {
137- connection.set(" scm:git:git://github.com/$githubOrganization /$repoName .git" )
138- developerConnection.set(" scm:git:ssh://github.com/$githubOrganization /$repoName .git" )
139- url.set(" https://github.com/$githubOrganization /$repoName " )
140- }
141-
142- artifact(javadocJar)
143- }
144- }
145- }
146-
147- if (project.hasProperty(SIGNING_KEY_PROP ) && project.hasProperty(SIGNING_PASSWORD_PROP )) {
148- apply (plugin = " signing" )
149- extensions.configure<SigningExtension > {
150- useInMemoryPgpKeys(
151- project.property(SIGNING_KEY_PROP ) as String ,
152- project.property(SIGNING_PASSWORD_PROP ) as String ,
153- )
154- sign(publications)
155- }
156-
157- // FIXME - workaround for https://github.com/gradle/gradle/issues/26091
158- val signingTasks = tasks.withType<Sign >()
159- tasks.withType<AbstractPublishToMaven >().configureEach {
160- mustRunAfter(signingTasks)
161- }
162- }
163- }
164-
165- fun isAvailableForNexusPublication (project : Project , publication : MavenPublication ): Boolean {
166- var shouldPublish = true
167-
168- // Check SKIP_PUBLISH_PROP
169- if (project.extra.has(Properties .SKIP_PUBLISHING )) shouldPublish = false
170-
171- // Only publish publications with the configured group from JReleaser or everything if JReleaser group is not configured
172- val publishGroupName = project.findProperty(PUBLISH_GROUP_NAME_PROP ) as ? String
173- shouldPublish = shouldPublish && (publishGroupName == null || publication.groupId.startsWith(publishGroupName))
174-
175- // Validate publication name is allowed to be published
176- shouldPublish = shouldPublish && ALLOWED_PUBLICATION_NAMES .any { publication.name.equals(it, ignoreCase = true ) }
177-
178- return shouldPublish
179- }
180-
181- tasks.withType<AbstractPublishToMaven >().configureEach {
182- onlyIf {
183- isAvailableForNexusPublication(project, publication).also {
184- if (! it) {
185- logger.warn(" Skipping publication, project=${project.name} ; publication=${publication.name} ; group=${publication.groupId} " )
186- }
187- }
188- }
189- }
190- }
191-
19274/* *
19375 * Configure publishing for this project. This applies the `maven-publish` and `signing` plugins and configures
19476 * the publications.
@@ -276,152 +158,6 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = "
276158 }
277159}
278160
279- /* *
280- * Configure nexus publishing plugin. This (conditionally) enables the `gradle-nexus.publish-plugin` and configures it.
281- */
282- fun Project.configureNexus (
283- nexusUrl : String = "https : // ossrh-staging-api.central.sonatype.com/service/local/",
284- snapshotRepositoryUrl : String = "https : // central.sonatype.com/repository/maven-snapshots/",
285- ) {
286- verifyRootProject { " Kotlin SDK nexus configuration must be applied to the root project only" }
287-
288- val requiredProps = listOf (SONATYPE_USERNAME_PROP , SONATYPE_PASSWORD_PROP , PUBLISH_GROUP_NAME_PROP )
289- val doConfigure = requiredProps.all { project.hasProperty(it) }
290- if (! doConfigure) {
291- logger.info(" skipping nexus configuration, missing one or more required properties: $requiredProps " )
292- return
293- }
294-
295- apply (plugin = " io.github.gradle-nexus.publish-plugin" )
296- extensions.configure<NexusPublishExtension > {
297- val publishGroupName = project.property(PUBLISH_GROUP_NAME_PROP ) as String
298- group = publishGroupName
299- packageGroup.set(publishGroupName)
300- repositories {
301- create(" awsNexus" ) {
302- this .nexusUrl.set(uri(nexusUrl))
303- this .snapshotRepositoryUrl.set(uri(snapshotRepositoryUrl))
304- username.set(project.property(SONATYPE_USERNAME_PROP ) as String )
305- password.set(project.property(SONATYPE_PASSWORD_PROP ) as String )
306- }
307- }
308-
309- transitionCheckOptions {
310- maxRetries.set(180 )
311- delayBetween.set(Duration .ofSeconds(10 ))
312- }
313- }
314- }
315-
316- /* *
317- * Configure JReleaser publishing plugin. This (conditionally) enables the `org.jreleaser` plugin and configures it.
318- */
319- fun Project.configureJReleaser () {
320- verifyRootProject { " JReleaser configuration must be applied to the root project only" }
321-
322- val requiredVariables = listOf (
323- EnvironmentVariables .MAVEN_CENTRAL_USERNAME ,
324- EnvironmentVariables .MAVEN_CENTRAL_TOKEN ,
325- EnvironmentVariables .GENERIC_TOKEN ,
326- )
327-
328- if (! requiredVariables.all { ! System .getenv(it).isNullOrBlank() }) {
329- logger.warn(" Skipping JReleaser configuration, missing one or more required environment variables: ${requiredVariables.joinToString()} " )
330- return
331- }
332-
333- // Collect a set of native artifact IDs (with platform suffix removed) from every project
334- val nativeArtifactIds = providers.provider {
335- allprojects.flatMap {
336- it.extensions.findByType(PublishingExtension ::class .java)
337- ?.publications
338- ?.withType(MavenPublication ::class .java)
339- ?.filter { it.name in ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES }
340- ?.map {
341- // Remove platform from artifact ID. This allows us to register artifact overrides for _all_ platforms,
342- // not just for the targets enabled on the current host.
343- var artifactIdWithoutPlatform = it.artifactId
344- ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES .forEach { platform ->
345- artifactIdWithoutPlatform = artifactIdWithoutPlatform.removeSuffix(" -${platform.lowercase()} " )
346- }
347- artifactIdWithoutPlatform
348- }
349- ? : emptySet()
350- }.toSet()
351- }
352-
353- apply (plugin = " org.jreleaser" )
354- extensions.configure<JReleaserExtension > {
355- project {
356- version = providers.gradleProperty(" sdkVersion" ).get()
357- }
358-
359- // JReleaser requires a releaser to be configured even though we don't use it.
360- // https://github.com/jreleaser/jreleaser/discussions/1725#discussioncomment-10674529
361- release {
362- generic {
363- skipRelease = true
364- }
365- }
366-
367- // We don't announce our releases anywhere
368- // https://jreleaser.org/guide/latest/reference/announce/index.html
369- announce {
370- active = Active .NEVER
371- }
372-
373- deploy {
374- maven {
375- mavenCentral {
376- create(" maven-central" ) {
377- active = Active .ALWAYS // the MavenDeployer default is ALWAYS, but MavenCentralDeployer is NEVER
378- url = " https://central.sonatype.com/api/v1/publisher"
379- stagingRepository(rootProject.layout.buildDirectory.dir(" m2" ).get().toString())
380-
381- maxRetries = 100
382- retryDelay = 60 // seconds
383- snapshotSupported = false // do not allow publication of snapshot artifacts
384- applyMavenCentralRules = true
385- sign = false // Signing is done when publishing, see the 'configurePublishing' function
386- // all of the following should be enabled by applyMavenCentralRules but set them explicitly to be sure
387- checksums = true
388- sourceJar = true
389- javadocJar = true
390- verifyPom = true
391-
392- artifacts {
393- artifactOverride {
394- artifactId = " version-catalog"
395-
396- // Version catalogs don't produce JARs
397- jar = false
398- sourceJar = false
399- javadocJar = false
400-
401- // JReleaser fails when processing <packaging>toml</packaging> tag: `Unknown packaging: toml`
402- verifyPom = false
403- }
404- gradle.projectsEvaluated {
405- nativeArtifactIds.get().forEach { artifactIdWithoutPlatform ->
406- // Add an artifact override rule for each platform
407- ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES .forEach { platform ->
408- logger.info(" Configuring JReleaser artifact override for $artifactIdWithoutPlatform -${platform.lowercase()} " )
409- artifactOverride {
410- artifactId = " $artifactIdWithoutPlatform -${platform.lowercase()} "
411- jar = false // Native artifacts produce klibs, not JARs
412- verifyPom = false // JReleaser fails when processing <packaging>klib</packaging> tag: `Unknown packaging: klib`
413- }
414- }
415- }
416- }
417- }
418- }
419- }
420- }
421- }
422- }
423- }
424-
425161internal fun isAvailableForPublication (project : Project , publication : MavenPublication ): Boolean {
426162 var shouldPublish = true
427163
0 commit comments