Skip to content

Commit f7224f4

Browse files
authored
Maven publishing, more fixes (#43)
* still mucking about, trying to get gradle publishing working properly * fix maven central badge
1 parent d22e21c commit f7224f4

File tree

4 files changed

+59
-39
lines changed

4 files changed

+59
-39
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![Status](https://img.shields.io/badge/status-proof--of--concept-blueviolet?style=flat-square)](https://github.com/adamko-dev/kotlinx-serialization-typescript-generator#status)
22
[![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)
3-
[![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)
3+
[![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)
44
[![](https://jitpack.io/v/adamko-dev/kotlinx-serialization-typescript-generator.svg?style=flat-square)](https://jitpack.io/#adamko-dev/kotlinx-serialization-typescript-generator)
55

66
# Kotlinx Serialization TypeScript Generator

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import buildsrc.config.excludeGeneratedGradleDsl
22

33
plugins {
4-
base
54
idea
65
id("me.qoomon.git-versioning")
76
id("org.jetbrains.kotlinx.kover")
@@ -27,6 +26,7 @@ tasks.wrapper {
2726
distributionType = Wrapper.DistributionType.ALL
2827
}
2928

29+
3030
idea {
3131
module {
3232
isDownloadSources = true

buildSrc/src/main/kotlin/buildsrc/convention/maven-publish.gradle.kts

+53-33
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,41 @@ val signingSecretKeyRingFile: Provider<String> =
3636
providers.gradleProperty("signing.secretKeyRingFile")
3737

3838

39-
val javadocJarStub by tasks.registering(Jar::class) {
40-
group = JavaBasePlugin.DOCUMENTATION_GROUP
41-
description = "Stub javadoc.jar artifact (required by Maven Central)"
42-
archiveClassifier.set("javadoc")
43-
}
44-
4539

4640
tasks.withType<AbstractPublishToMaven>().configureEach {
4741
// Gradle warns about some signing tasks using publishing task outputs without explicit
4842
// dependencies. I'm not going to go through them all and fix them, so here's a quick fix.
4943
dependsOn(tasks.withType<Sign>())
5044

45+
doLast {
46+
logger.lifecycle("[${this.name}] ${project.group}:${project.name}:${project.version}")
47+
}
48+
}
49+
50+
51+
signing {
5152
if (sonatypeRepositoryCredentials.isPresent()) {
52-
dependsOn(javadocJarStub)
53+
if (signingKeyId.isPresent() && signingKey.isPresent() && signingPassword.isPresent()) {
54+
useInMemoryPgpKeys(signingKeyId.get(), signingKey.get(), signingPassword.get())
55+
} else {
56+
useGpgCmd()
57+
}
5358
}
59+
}
5460

55-
doLast {
56-
logger.lifecycle("[${this.name}] ${project.group}:${project.name}:${project.version}")
61+
62+
afterEvaluate {
63+
// Register signatures afterEvaluate, otherwise the signing plugin creates the signing tasks
64+
// too early, before all the publications are added.
65+
// Use .all { }, not .configureEach { }, otherwise the signing plugin doesn't create the tasks
66+
// soon enough.
67+
publishing.publications.withType<MavenPublication>().all {
68+
signing.sign(this)
69+
logger.lifecycle("configuring signature for publication ${this.name}")
5770
}
5871
}
5972

73+
val javadocJarStub = javadocStubTask()
6074

6175
publishing {
6276
if (sonatypeRepositoryCredentials.isPresent()) {
@@ -65,11 +79,10 @@ publishing {
6579
name = "sonatype"
6680
credentials(sonatypeRepositoryCredentials.get())
6781
}
68-
// publish to local dir, for testing
69-
// maven {
70-
// name = "maven-internal"
71-
// url = uri(rootProject.layout.buildDirectory.dir("maven-internal"))
72-
// }
82+
// // publish to local dir, for testing
83+
// maven(rootProject.layout.buildDirectory.dir("maven-internal")) {
84+
// name = "maven-internal"
85+
// }
7386
}
7487
publications.withType<MavenPublication>().configureEach {
7588
createKxsTsGenPom()
@@ -79,29 +92,14 @@ publishing {
7992
}
8093

8194

82-
signing {
83-
if (sonatypeRepositoryCredentials.isPresent()) {
84-
if (signingKeyId.isPresent() && signingKey.isPresent() && signingPassword.isPresent()) {
85-
useInMemoryPgpKeys(signingKeyId.get(), signingKey.get(), signingPassword.get())
86-
} else {
87-
useGpgCmd()
88-
}
89-
90-
// sign all publications
91-
sign(publishing.publications)
92-
sign(javadocJarStub.get())
93-
}
94-
}
95-
96-
97-
plugins.withType(KotlinMultiplatformPlugin::class).configureEach {
95+
plugins.withType<KotlinMultiplatformPlugin>().configureEach {
9896
publishing.publications.withType<MavenPublication>().configureEach {
99-
artifact(javadocJarStub)
97+
// artifact(javadocJarStub)
10098
}
10199
}
102100

103101

104-
plugins.withType(JavaPlugin::class).configureEach {
102+
plugins.withType<JavaPlugin>().configureEach {
105103
afterEvaluate {
106104
if (!isKotlinMultiplatformJavaEnabled()) {
107105
publishing.publications.create<MavenPublication>("mavenJava") {
@@ -113,8 +111,30 @@ plugins.withType(JavaPlugin::class).configureEach {
113111
}
114112

115113

116-
plugins.withType(JavaPlatformPlugin::class).configureEach {
114+
plugins.withType<JavaPlatformPlugin>().configureEach {
115+
// val javadocJarStub = javadocStubTask()
117116
publishing.publications.create<MavenPublication>("mavenJavaPlatform") {
118117
from(components["javaPlatform"])
118+
// artifact(javadocJarStub)
119119
}
120120
}
121+
122+
123+
fun Project.javadocStubTask(): Jar {
124+
125+
// use creating, not registering, because the signing plugin sucks
126+
val javadocJarStub by tasks.creating(Jar::class) {
127+
group = JavaBasePlugin.DOCUMENTATION_GROUP
128+
description = "Stub javadoc.jar artifact (required by Maven Central)"
129+
archiveClassifier.set("javadoc")
130+
}
131+
132+
val signingTasks = signing.sign(javadocJarStub)
133+
134+
tasks.withType<AbstractPublishToMaven>().all {
135+
dependsOn(javadocJarStub)
136+
signingTasks.forEach { dependsOn(it) }
137+
}
138+
139+
return javadocJarStub
140+
}

gradle/libs.versions.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ kotlinx-serialization-cbor = { group = "org.jetbrains.kotlinx", name = "kotlinx-
4343
okio-bom = { group = "com.squareup.okio", name = "okio-bom", version.ref = "okio" }
4444
okio-core = { group = "com.squareup.okio", name = "okio" }
4545

46-
kotlinx-kover-gradlePlugin = { group = "org.jetbrains.kotlinx", name = "kover", version.ref = "kotlinx-kover" }
47-
48-
gradleNodePlugin = { group = "com.github.node-gradle", name = "gradle-node-plugin", version.ref = "gradleNodePlugin" }
49-
5046
classgraph = { group = "io.github.classgraph", name = "classgraph", version.ref = "classgraph" }
5147

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

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

75+
gradleNodePlugin = { group = "com.github.node-gradle", name = "gradle-node-plugin", version.ref = "gradleNodePlugin" }
76+
77+
kotlinx-kover-gradlePlugin = { group = "org.jetbrains.kotlinx", name = "kover", version.ref = "kotlinx-kover" }
78+
7979
[bundles]
8080

8181
[plugins]

0 commit comments

Comments
 (0)