Skip to content

Maven publishing, more fixes #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Status](https://img.shields.io/badge/status-proof--of--concept-blueviolet?style=flat-square)](https://github.com/adamko-dev/kotlinx-serialization-typescript-generator#status)
[![GitHub license](https://img.shields.io/github/license/adamko-dev/kotlinx-serialization-typescript-generator?style=flat-square)](https://github.com/adamko-dev/kotlinx-serialization-typescript-generator/blob/main/LICENSE)
[![Maven Central](https://img.shields.io/maven-central/v/dev.adamko.txstsgen/kxs-ts-gen-core?style=flat-square)](https://search.maven.org/search?q=g:dev.adamko.kxstsgen)
[![Maven Central](https://img.shields.io/maven-central/v/dev.adamko.kxstsgen/kxs-ts-gen-core?color=%234c1&style=flat-square)](https://search.maven.org/search?q=g:dev.adamko.kxstsgen)
[![](https://jitpack.io/v/adamko-dev/kotlinx-serialization-typescript-generator.svg?style=flat-square)](https://jitpack.io/#adamko-dev/kotlinx-serialization-typescript-generator)

# Kotlinx Serialization TypeScript Generator
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import buildsrc.config.excludeGeneratedGradleDsl

plugins {
base
idea
id("me.qoomon.git-versioning")
id("org.jetbrains.kotlinx.kover")
Expand All @@ -27,6 +26,7 @@ tasks.wrapper {
distributionType = Wrapper.DistributionType.ALL
}


idea {
module {
isDownloadSources = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,41 @@ val signingSecretKeyRingFile: Provider<String> =
providers.gradleProperty("signing.secretKeyRingFile")


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 {
// Gradle warns about some signing tasks using publishing task outputs without explicit
// dependencies. I'm not going to go through them all and fix them, so here's a quick fix.
dependsOn(tasks.withType<Sign>())

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


signing {
if (sonatypeRepositoryCredentials.isPresent()) {
dependsOn(javadocJarStub)
if (signingKeyId.isPresent() && signingKey.isPresent() && signingPassword.isPresent()) {
useInMemoryPgpKeys(signingKeyId.get(), signingKey.get(), signingPassword.get())
} else {
useGpgCmd()
}
}
}

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

afterEvaluate {
// Register signatures afterEvaluate, otherwise the signing plugin creates the signing tasks
// too early, before all the publications are added.
// Use .all { }, not .configureEach { }, otherwise the signing plugin doesn't create the tasks
// soon enough.
publishing.publications.withType<MavenPublication>().all {
signing.sign(this)
logger.lifecycle("configuring signature for publication ${this.name}")
}
}

val javadocJarStub = javadocStubTask()

publishing {
if (sonatypeRepositoryCredentials.isPresent()) {
Expand All @@ -65,11 +79,10 @@ publishing {
name = "sonatype"
credentials(sonatypeRepositoryCredentials.get())
}
// publish to local dir, for testing
// maven {
// name = "maven-internal"
// url = uri(rootProject.layout.buildDirectory.dir("maven-internal"))
// }
// // publish to local dir, for testing
// maven(rootProject.layout.buildDirectory.dir("maven-internal")) {
// name = "maven-internal"
// }
}
publications.withType<MavenPublication>().configureEach {
createKxsTsGenPom()
Expand All @@ -79,29 +92,14 @@ publishing {
}


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)
sign(javadocJarStub.get())
}
}


plugins.withType(KotlinMultiplatformPlugin::class).configureEach {
plugins.withType<KotlinMultiplatformPlugin>().configureEach {
publishing.publications.withType<MavenPublication>().configureEach {
artifact(javadocJarStub)
// artifact(javadocJarStub)
}
}


plugins.withType(JavaPlugin::class).configureEach {
plugins.withType<JavaPlugin>().configureEach {
afterEvaluate {
if (!isKotlinMultiplatformJavaEnabled()) {
publishing.publications.create<MavenPublication>("mavenJava") {
Expand All @@ -113,8 +111,30 @@ plugins.withType(JavaPlugin::class).configureEach {
}


plugins.withType(JavaPlatformPlugin::class).configureEach {
plugins.withType<JavaPlatformPlugin>().configureEach {
// val javadocJarStub = javadocStubTask()
publishing.publications.create<MavenPublication>("mavenJavaPlatform") {
from(components["javaPlatform"])
// artifact(javadocJarStub)
}
}


fun Project.javadocStubTask(): Jar {

// use creating, not registering, because the signing plugin sucks
val javadocJarStub by tasks.creating(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Stub javadoc.jar artifact (required by Maven Central)"
archiveClassifier.set("javadoc")
}

val signingTasks = signing.sign(javadocJarStub)

tasks.withType<AbstractPublishToMaven>().all {
dependsOn(javadocJarStub)
signingTasks.forEach { dependsOn(it) }
}

return javadocJarStub
}
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ kotlinx-serialization-cbor = { group = "org.jetbrains.kotlinx", name = "kotlinx-
okio-bom = { group = "com.squareup.okio", name = "okio-bom", version.ref = "okio" }
okio-core = { group = "com.squareup.okio", name = "okio" }

kotlinx-kover-gradlePlugin = { group = "org.jetbrains.kotlinx", name = "kover", version.ref = "kotlinx-kover" }

gradleNodePlugin = { group = "com.github.node-gradle", name = "gradle-node-plugin", version.ref = "gradleNodePlugin" }

classgraph = { group = "io.github.classgraph", name = "classgraph", version.ref = "classgraph" }

kotlinProcess = { group = "com.github.pgreze", name = "kotlin-process", version.ref = "kotlinProcess" }
Expand Down Expand Up @@ -76,6 +72,10 @@ kotlinx-knit-gradlePlugin = { group = "org.jetbrains.kotlinx", name = "kotlinx-k

gitVersioningPlugin = { group = "me.qoomon", name = "gradle-git-versioning-plugin", version.ref = "gitVersioningPlugin" }

gradleNodePlugin = { group = "com.github.node-gradle", name = "gradle-node-plugin", version.ref = "gradleNodePlugin" }

kotlinx-kover-gradlePlugin = { group = "org.jetbrains.kotlinx", name = "kover", version.ref = "kotlinx-kover" }

[bundles]

[plugins]