11package buildsrc.convention
22
3+ import buildsrc.config.createKxsTsGenPom
4+ import buildsrc.config.credentialsAction
5+ import buildsrc.config.isKotlinMultiplatformJavaEnabled
36import buildsrc.config.publishing
47import buildsrc.config.signing
5- import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
68import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin
7- import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
89
910
1011plugins {
@@ -13,15 +14,8 @@ plugins {
1314}
1415
1516val sonatypeRepositoryCredentials: Provider <Action <PasswordCredentials >> =
16- providers.zip(
17- providers.gradleProperty(" sonatypeRepositoryUsername" ),
18- providers.gradleProperty(" sonatypeRepositoryPassword" ),
19- ) { user, pass ->
20- Action <PasswordCredentials > {
21- username = user
22- password = pass
23- }
24- }
17+ providers.credentialsAction(" sonatypeRepository" )
18+
2519
2620val sonatypeRepositoryReleaseUrl: Provider <String > = provider {
2721 if (version.toString().endsWith(" SNAPSHOT" )) {
@@ -49,36 +43,36 @@ val javadocJarStub by tasks.registering(Jar::class) {
4943}
5044
5145
52- tasks.matching {
53- it.name.startsWith(PublishingPlugin .PUBLISH_LIFECYCLE_TASK_NAME )
54- && it.group == PublishingPlugin .PUBLISH_TASK_GROUP
55- }.configureEach {
46+ tasks.withType<AbstractPublishToMaven >().configureEach {
47+ // Gradle warns about some signing tasks using publishing task outputs without explicit
48+ // dependencies. I'm not going to go through them all and fix them, so here's a quick fix.
49+ dependsOn(tasks.withType<Sign >())
50+
5651 if (sonatypeRepositoryCredentials.isPresent()) {
5752 dependsOn(javadocJarStub)
5853 }
54+
5955 doLast {
6056 logger.lifecycle(" [${this .name} ] ${project.group} :${project.name} :${project.version} " )
6157 }
6258}
6359
6460
65- // Gradle warns about some signing tasks using publishing task outputs without explicit
66- // dependencies. I'm not going to go through them all and fix them, so here's a quick safety check.
67- tasks.matching { it.name.startsWith(" publish" ) }.configureEach {
68- mustRunAfter(tasks.matching { it.name.startsWith(" sign" ) })
69- }
70-
71-
7261publishing {
7362 if (sonatypeRepositoryCredentials.isPresent()) {
7463 repositories {
7564 maven(sonatypeRepositoryReleaseUrl) {
7665 name = " sonatype"
7766 credentials(sonatypeRepositoryCredentials.get())
7867 }
68+ // publish to local dir, for testing
69+ // maven {
70+ // name = "maven-internal"
71+ // url = uri(rootProject.layout.buildDirectory.dir("maven-internal"))
72+ // }
7973 }
8074 publications.withType<MavenPublication >().configureEach {
81- createKxTsGenPom ()
75+ createKxsTsGenPom ()
8276 artifact(javadocJarStub)
8377 }
8478 }
@@ -124,40 +118,3 @@ plugins.withType(JavaPlatformPlugin::class).configureEach {
124118 from(components[" javaPlatform" ])
125119 }
126120}
127-
128-
129- fun MavenPublication.createKxTsGenPom (): Unit = pom {
130- name.set(" Kotlinx Serialization Typescript Generator" )
131- description.set(" KxTsGen creates TypeScript interfaces from Kotlinx Serialization @Serializable classes" )
132- url.set(" https://github.com/adamko-dev/kotlinx-serialization-typescript-generator" )
133-
134- licenses {
135- license {
136- name.set(" The Apache License, Version 2.0" )
137- url.set(" https://www.apache.org/licenses/LICENSE-2.0.txt" )
138- }
139- }
140-
141- developers {
142- developer {
143- email.set(" adam@adamko.dev" )
144- }
145- }
146-
147- scm {
148- connection.set(" scm:git:git://github.com/adamko-dev/kotlinx-serialization-typescript-generator.git" )
149- developerConnection.set(" scm:git:ssh://github.com:adamko-dev/kotlinx-serialization-typescript-generator.git" )
150- url.set(" https://github.com/adamko-dev/kotlinx-serialization-typescript-generator" )
151- }
152- }
153-
154-
155- /* * Logic from [KotlinJvmTarget.withJava] */
156- fun Project.isKotlinMultiplatformJavaEnabled (): Boolean {
157- val multiplatformExtension: KotlinMultiplatformExtension ? =
158- extensions.findByType(KotlinMultiplatformExtension ::class )
159-
160- return multiplatformExtension?.targets
161- ?.any { it is KotlinJvmTarget && it.withJavaEnabled }
162- ? : false
163- }
0 commit comments