Skip to content

Commit

Permalink
Preparation for Maven Central release (#22)
Browse files Browse the repository at this point in the history
* update build config to prep for Maven Central publishing

* add KTable mapValues tests

* kdoc some functions

* polishing Maven publishing + POM
  • Loading branch information
aSemy authored Aug 6, 2022
1 parent f28f605 commit 214c5cf
Show file tree
Hide file tree
Showing 18 changed files with 321 additions and 136 deletions.
8 changes: 8 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ gitVersioning.apply {
rev { version = "\${commit}" }
}


dependencies {
implementation(platform(projects.modules.versionsPlatform))

Expand All @@ -28,6 +29,13 @@ dependencies {
api(projects.modules.kotkaStreamsKotlinxSerialization)
}


kotkaPublishing {
mavenPomSubprojectName.set("Kotlin for Kafka Streams")
mavenPomDescription.set("Using Kotka means a more pleasant experience while using Kafka Streams")
}


tasks.wrapper {
gradleVersion = "7.5.1"
distributionType = Wrapper.DistributionType.ALL
Expand Down
6 changes: 2 additions & 4 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`kotlin-dsl`
kotlin("jvm") version "1.6.21"
kotlin("jvm") version embeddedKotlinVersion
}

dependencies {
Expand All @@ -14,18 +14,16 @@ dependencies {
implementation(libs.kotlin.gradlePlugin)

implementation(libs.gitVersioningPlugin)
implementation(libs.dokkaPlugin)
}

val gradleJvmTarget = "1.8"
val gradleJvmVersion = "8"
val gradleKotlinTarget = "1.6"

tasks.withType<KotlinCompile>().configureEach {

kotlinOptions {
jvmTarget = gradleJvmTarget
apiVersion = gradleKotlinTarget
languageVersion = gradleKotlinTarget
}

kotlinOptions.freeCompilerArgs += listOf(
Expand Down
26 changes: 11 additions & 15 deletions buildSrc/src/main/kotlin/buildsrc/convention/kotlin-jvm.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package buildsrc.convention

import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.`java-library`
import org.gradle.kotlin.dsl.kotlin
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile


plugins {
id("buildsrc.convention.subproject")
kotlin("jvm")
`java-library`
id("org.jetbrains.dokka")
}


Expand All @@ -28,32 +26,25 @@ dependencies {
}


val projectJvmTarget = "1.8"
val projectJvmVersion = "8"
val projectKotlinTarget = "1.6"


kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(projectJvmVersion))
languageVersion.set(JavaLanguageVersion.of(11))
}
}


tasks.withType<KotlinCompile>().configureEach {

kotlinOptions {
jvmTarget = projectJvmTarget
apiVersion = projectKotlinTarget
languageVersion = projectKotlinTarget
jvmTarget = "1.8"
apiVersion = "1.5"
languageVersion = "1.7"
}

kotlinOptions.freeCompilerArgs += listOf(
"-opt-in=kotlin.RequiresOptIn",
"-opt-in=kotlin.ExperimentalStdlibApi",
"-opt-in=kotlin.time.ExperimentalTime",
// "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
// "-opt-in=kotlinx.serialization.ExperimentalSerializationApi",
)
}

Expand All @@ -72,3 +63,8 @@ java {
withJavadocJar()
withSourcesJar()
}


tasks.withType<Jar>().named("javadocJar") {
from(tasks.dokkaHtml)
}
132 changes: 58 additions & 74 deletions buildSrc/src/main/kotlin/buildsrc/convention/maven-publish.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,44 +1,22 @@
package buildsrc.convention

import kotka.ext.createKotkaStreamsPom
import kotka.ext.credentialsAction
import kotka.ext.publishing
import org.gradle.kotlin.dsl.maven
import org.gradle.kotlin.dsl.`maven-publish`
import org.gradle.kotlin.dsl.registering
import org.gradle.kotlin.dsl.withType
import buildsrc.ext.KotkaPublishingSettings
import buildsrc.ext.createKotkaStreamsPom
import buildsrc.ext.gavString


plugins {
`maven-publish`
// signing
signing
}


val sonatypeRepositoryCredentials: Provider<Action<PasswordCredentials>> =
providers.credentialsAction("sonatypeRepository")

val gitHubPackagesCredentials: Provider<Action<PasswordCredentials>> =
providers.credentialsAction("GitHubPackages")


val sonatypeRepositoryReleaseUrl: Provider<String> = provider {
if (version.toString().endsWith("SNAPSHOT")) {
"https://s01.oss.sonatype.org/content/repositories/snapshots/"
} else {
"https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
}
}


val signingKeyId: Provider<String> =
providers.gradleProperty("signing.keyId")
val signingKey: Provider<String> =
providers.gradleProperty("signing.key")
val signingPassword: Provider<String> =
providers.gradleProperty("signing.password")
val signingSecretKeyRingFile: Provider<String> =
providers.gradleProperty("signing.secretKeyRingFile")
val kotkaPublishingSettings: KotkaPublishingSettings =
extensions.create(
KotkaPublishingSettings.NAME,
KotkaPublishingSettings::class,
project,
)


tasks.withType<AbstractPublishToMaven>().configureEach {
Expand All @@ -47,79 +25,85 @@ tasks.withType<AbstractPublishToMaven>().configureEach {
dependsOn(tasks.withType<Sign>())

doLast {
logger.lifecycle("[${this.name}] ${project.group}:${project.name}:${project.version}")
logger.lifecycle("[${this.name}] ${publication.gavString}")
}
}


//signing {
// if (sonatypeRepositoryCredentials.isPresent) {
// if (signingKeyId.isPresent && signingKey.isPresent && signingPassword.isPresent) {
// useInMemoryPgpKeys(signingKeyId.get(), signingKey.get(), signingPassword.get())
// } else {
// useGpgCmd()
// }
//
// // sign all publications
// sign(publishing.publications)
// }
//}
// signing must be configured *after* publications are created
fun Project.configureSigning() = signing {
with(kotkaPublishingSettings) {
if (signingKeyId.isPresent && signingKey.isPresent && signingPassword.isPresent) {
useInMemoryPgpKeys(signingKeyId.get(), signingKey.get(), signingPassword.get())
// sign all publications
sign(publishing.publications)
}
}
}


publishing {
repositories {
// publish to local dir, for testing
maven(rootProject.layout.buildDirectory.dir("maven-internal")) {
name = "maven-internal"
name = "ProjectLocalDir"
}

// if (sonatypeRepositoryCredentials.isPresent) {
// maven(sonatypeRepositoryReleaseUrl) {
// name = "sonatype"
// credentials(sonatypeRepositoryCredentials.get())
// }
// }
//
// if (gitHubPackagesCredentials.isPresent) {
// maven("https://maven.pkg.github.com/adamko-dev/kotka-streams") {
// name = "GitHubPackages"
// credentials(gitHubPackagesCredentials.get())
// }
// }
with(kotkaPublishingSettings) {
if (sonatypeRepositoryCredentials.isPresent) {
maven(sonatypeRepositoryReleaseUrl) {
name = "Sonatype"
credentials(sonatypeRepositoryCredentials.get())
}
}

if (gitHubPackagesCredentials.isPresent) {
maven("https://maven.pkg.github.com/adamko-dev/kotka-streams") {
name = "GitHubPackages"
credentials(gitHubPackagesCredentials.get())
}
}
}
}

publications.withType<MavenPublication>().configureEach {
createKotkaStreamsPom()
createKotkaStreamsPom {
name.set(kotkaPublishingSettings.mavenPomSubprojectName.map {
"Kotka Streams :: $it"
})
description.set(kotkaPublishingSettings.mavenPomDescription)
}
}
}


plugins.withType<JavaPlugin>().configureEach {
publishing.publications.create<MavenPublication>("mavenJava") {
from(components["java"])
// artifact(tasks["sourcesJar"])
}

configureSigning()
}


plugins.withType<JavaPlatformPlugin>().configureEach {

val javadocJarStub by tasks.registering(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Stub javadoc.jar artifact (required by Maven Central)"
archiveClassifier.set("javadoc")
}

tasks.withType<AbstractPublishToMaven>().configureEach {
dependsOn(javadocJarStub)
}

// if (sonatypeRepositoryCredentials.isPresent) {
// signing.sign(javadocJarStub.get())
// Javadoc might not be necesary as the 'pom packaging' is 'pom'?
// val javadocJarStub by tasks.registering(Jar::class) {
// group = JavaBasePlugin.DOCUMENTATION_GROUP
// description = "Stub javadoc.jar artifact (required by Maven Central)"
// archiveClassifier.set("javadoc")
// }

publishing.publications.create<MavenPublication>("mavenJavaPlatform") {
from(components["javaPlatform"])
artifact(javadocJarStub)
// artifact(javadocJarStub)
}

configureSigning()
}

// workaround for https://github.com/gradle/gradle/issues/16543
inline fun <reified T : Task> TaskContainer.provider(taskName: String): Provider<T> =
providers.provider { taskName }
.flatMap { named<T>(it) }
50 changes: 50 additions & 0 deletions buildSrc/src/main/kotlin/buildsrc/ext/KotkaPublishingSettings.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package buildsrc.ext

import javax.inject.Inject
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.artifacts.repositories.PasswordCredentials
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.provider.ProviderFactory


abstract class KotkaPublishingSettings @Inject constructor(
providers: ProviderFactory,

project: Project,
) {

abstract val mavenPomSubprojectName: Property<String>
abstract val mavenPomDescription: Property<String>

val gitHubPackagesCredentials: Provider<Action<PasswordCredentials>> =
providers.credentialsAction("GitHubPackages")


val sonatypeRepositoryCredentials: Provider<Action<PasswordCredentials>> =
providers.credentialsAction("sonatypeRepository")

val sonatypeRepositoryReleaseUrl: Provider<String> = providers.provider {
if (project.version.toString().endsWith("SNAPSHOT")) {
"https://s01.oss.sonatype.org/content/repositories/snapshots/"
} else {
"https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
}
}


val signingKeyId: Provider<String> =
providers.gradleProperty("signing.keyId")
val signingKey: Provider<String> =
providers.gradleProperty("signing.key")
val signingPassword: Provider<String> =
providers.gradleProperty("signing.password")
val signingSecretKeyRingFile: Provider<String> =
providers.gradleProperty("signing.secretKeyRingFile")


companion object {
const val NAME = "kotkaPublishing"
}
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/buildsrc/ext/gradle.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kotka.ext
package buildsrc.ext

import org.gradle.api.Action
import org.gradle.api.artifacts.repositories.PasswordCredentials
Expand Down
Loading

0 comments on commit 214c5cf

Please sign in to comment.