Skip to content

Commit 960ffed

Browse files
committed
Refactor for aws-sdk-kotlin K/N publishing
1 parent f8101dc commit 960ffed

File tree

2 files changed

+2
-265
lines changed
  • build-plugins

2 files changed

+2
-265
lines changed

build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt

Lines changed: 1 addition & 260 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,6 @@ private object Properties {
2525
const val SKIP_PUBLISHING = "skipPublish"
2626
}
2727

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-
4628
private const val SIGNING_PUBLIC_KEY = "SIGNING_KEY"
4729
private const val SIGNING_SECRET_KEY = "SIGNING_PASSWORD"
4830

@@ -80,6 +62,7 @@ private val ALLOWED_KOTLIN_NATIVE_GROUP_NAMES = setOf(
8062
"aws.sdk.kotlin.crt",
8163
"aws.smithy.kotlin",
8264
"com.sonatype.central.testing.amazon",
65+
"aws.sdk.kotlin",
8366
)
8467

8568
// Optional override to the above set.
@@ -93,102 +76,6 @@ fun Project.skipPublishing() {
9376
extra.set(Properties.SKIP_PUBLISHING, true)
9477
}
9578

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-
19279
/**
19380
* Configure publishing for this project. This applies the `maven-publish` and `signing` plugins and configures
19481
* the publications.
@@ -276,152 +163,6 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = "
276163
}
277164
}
278165

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-
425166
internal fun isAvailableForPublication(project: Project, publication: MavenPublication): Boolean {
426167
var shouldPublish = true
427168

build-plugins/kmp-conventions/src/main/kotlin/aws/sdk/kotlin/gradle/kmp/ConfigureTargets.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,7 @@ fun Project.configureKmpTargets() {
132132
kmpExt.apply { configureWindows() }
133133
}
134134
if ((hasLinux || hasDesktop) && (HostManager.hostIsLinux || NATIVE_ENABLE_ALL_TARGETS)) {
135-
if (group == "aws.sdk.kotlin.crt" || group == "aws.smithy.kotlin") { // TODO Remove special-casing once K/N is released across the entire project
136-
kmpExt.apply { configureLinux() }
137-
} else {
138-
kmpExt.apply { configureDummyLinux() }
139-
}
135+
kmpExt.apply { configureLinux() }
140136
}
141137
}
142138

0 commit comments

Comments
 (0)