@@ -2,6 +2,10 @@ package buildsrc.convention
2
2
3
3
import buildsrc.config.publishing
4
4
import buildsrc.config.signing
5
+ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
6
+ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin
7
+ import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
8
+
5
9
6
10
plugins {
7
11
`maven- publish`
@@ -28,92 +32,91 @@ val sonatypeRepositoryReleaseUrl: Provider<String> = provider {
28
32
29
33
val signingKeyId: Provider <String > =
30
34
providers.gradleProperty(" signing.keyId" )
35
+ val signingKey: Provider <String > =
36
+ providers.gradleProperty(" signing.key" )
31
37
val signingPassword: Provider <String > =
32
38
providers.gradleProperty(" signing.password" )
33
39
val signingSecretKeyRingFile: Provider <String > =
34
40
providers.gradleProperty(" signing.secretKeyRingFile" )
35
41
36
42
43
+ val javadocJarStub by tasks.registering(Jar ::class ) {
44
+ group = JavaBasePlugin .DOCUMENTATION_GROUP
45
+ description = " Stub javadoc.jar artifact (required by Maven Central)"
46
+ archiveClassifier.set(" javadoc" )
47
+ }
48
+
49
+
37
50
tasks.matching {
38
51
it.name.startsWith(PublishingPlugin .PUBLISH_LIFECYCLE_TASK_NAME )
39
52
&& it.group == PublishingPlugin .PUBLISH_TASK_GROUP
40
53
}.configureEach {
54
+ if (sonatypeRepositoryCredentials.isPresent()) {
55
+ dependsOn(javadocJarStub)
56
+ }
41
57
doLast {
42
58
logger.lifecycle(" [${this .name} ] ${project.group} :${project.name} :${project.version} " )
43
59
}
44
60
}
45
61
46
62
47
63
publishing {
48
- repositories {
49
- maven(sonatypeRepositoryReleaseUrl) {
50
- name = " sonatype"
51
- credentials(sonatypeRepositoryCredentials.get())
64
+ if (sonatypeRepositoryCredentials.isPresent()) {
65
+ repositories {
66
+ maven(sonatypeRepositoryReleaseUrl) {
67
+ name = " sonatype"
68
+ credentials(sonatypeRepositoryCredentials.get())
69
+ }
70
+ }
71
+ publications.withType<MavenPublication >().configureEach {
72
+ createKxTsGenPom()
73
+ artifact(javadocJarStub)
52
74
}
53
- }
54
- publications.withType<MavenPublication >().configureEach {
55
- createKxTsGenPom()
56
75
}
57
76
}
58
77
59
78
60
79
signing {
80
+ if (sonatypeRepositoryCredentials.isPresent()) {
81
+ if (signingKeyId.isPresent() && signingKey.isPresent() && signingPassword.isPresent()) {
82
+ useInMemoryPgpKeys(signingKeyId.get(), signingKey.get(), signingPassword.get())
83
+ } else {
84
+ useGpgCmd()
85
+ }
61
86
62
- // if (
63
- // signingKeyId.isPresent() &&
64
- // signingPassword.isPresent() &&
65
- // signingSecretKeyRingFile.isPresent()
66
- // ) {
67
- // useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
68
- // } else {
69
- // useGpgCmd()
70
- // }
87
+ // sign all publications
88
+ sign(publishing.publications)
89
+ sign(javadocJarStub.get())
90
+ }
91
+ }
71
92
72
- useGpgCmd()
73
93
74
- // sign all publications
75
- sign(publishing.publications)
94
+ plugins.withType(KotlinMultiplatformPlugin ::class ).configureEach {
95
+ publishing.publications.withType<MavenPublication >().configureEach {
96
+ artifact(javadocJarStub)
97
+ }
76
98
}
77
99
78
100
79
- plugins.configureEach {
80
- when (this ) {
81
- // not necessary? It looks like the plugin creates publications correctly?
82
- // is KotlinMultiplatformPlugin -> {
83
- //
84
- // // Stub javadoc.jar artifact (required by Maven Central?)
85
- // val javadocJar by tasks.registering(Jar::class) {
86
- // archiveClassifier.set("javadoc")
87
- // }
88
- //
89
- // publishing.publications.create<MavenPublication>("mavenKotlinMpp") {
90
- // from(components["kotlin"])
91
- // artifact(javadocJar)
92
- // artifact(tasks["sourcesJar"])
93
- // }
94
- // }
95
-
96
- // JavaPlugin clashes with KotlinMultiplatformPlugin?
97
- // causes error
98
- // Artifact kxs-ts-gen-core-jvm-maven-publish-SNAPSHOT.jar wasn't produced by this build
99
- // is JavaPlugin -> afterEvaluate {
100
- // if (!plugins.hasPlugin(KotlinMultiplatformPlugin::class)) {
101
- // publishing.publications.create<MavenPublication>("mavenJava") {
102
- // from(components["java"])
103
- // artifact(tasks["sourcesJar"])
104
- // }
105
- // }
106
- // }
107
-
108
- is JavaPlatformPlugin -> {
109
- publishing.publications.create<MavenPublication >(" mavenJavaPlatform" ) {
110
- from(components[" javaPlatform" ])
101
+ plugins.withType(JavaPlugin ::class ).configureEach {
102
+ afterEvaluate {
103
+ if (! isKotlinMultiplatformJavaEnabled()) {
104
+ publishing.publications.create<MavenPublication >(" mavenJava" ) {
105
+ from(components[" java" ])
106
+ artifact(tasks[" sourcesJar" ])
111
107
}
112
108
}
113
109
}
114
110
}
115
111
116
112
113
+ plugins.withType(JavaPlatformPlugin ::class ).configureEach {
114
+ publishing.publications.create<MavenPublication >(" mavenJavaPlatform" ) {
115
+ from(components[" javaPlatform" ])
116
+ }
117
+ }
118
+
119
+
117
120
fun MavenPublication.createKxTsGenPom (): Unit = pom {
118
121
name.set(" Kotlinx Serialization Typescript Generator" )
119
122
description.set(" KxTsGen creates TypeScript interfaces from Kotlinx Serialization @Serializable classes" )
@@ -122,7 +125,7 @@ fun MavenPublication.createKxTsGenPom(): Unit = pom {
122
125
licenses {
123
126
license {
124
127
name.set(" The Apache License, Version 2.0" )
125
- url.set(" http ://www.apache.org/licenses/LICENSE-2.0.txt" )
128
+ url.set(" https ://www.apache.org/licenses/LICENSE-2.0.txt" )
126
129
}
127
130
}
128
131
@@ -138,3 +141,14 @@ fun MavenPublication.createKxTsGenPom(): Unit = pom {
138
141
url.set(" https://github.com/adamko-dev/kotlinx-serialization-typescript-generator" )
139
142
}
140
143
}
144
+
145
+
146
+ /* * Logic from [KotlinJvmTarget.withJava] */
147
+ fun Project.isKotlinMultiplatformJavaEnabled (): Boolean {
148
+ val multiplatformExtension: KotlinMultiplatformExtension ? =
149
+ extensions.findByType(KotlinMultiplatformExtension ::class )
150
+
151
+ return multiplatformExtension?.targets
152
+ ?.any { it is KotlinJvmTarget && it.withJavaEnabled }
153
+ ? : false
154
+ }
0 commit comments