1414 * limitations under the License.
1515 */
1616
17+ import groovy.util.Node
18+ import groovy.util.NodeList
1719import org.gradle.api.publish.maven.internal.artifact.FileBasedMavenArtifact
1820import org.jetbrains.kotlin.gradle.dsl.*
1921import org.jetbrains.kotlin.gradle.plugin.mpp.*
@@ -202,52 +204,117 @@ subprojects {
202204 }
203205}
204206
207+ fun publishPlatformArtifactsInRootModule (platformPublication : MavenPublication ,
208+ kotlinMultiplatformPublication : MavenPublication ) {
209+ lateinit var platformXml: XmlProvider
210+
211+ platformPublication.pom.withXml { platformXml = this }
212+
213+ kotlinMultiplatformPublication.apply {
214+ pom.withXml {
215+ val root = asNode()
216+ // Remove the original content and add the content from the platform POM:
217+ root.children().toList().forEach { root.remove(it as Node ) }
218+ platformXml.asNode().children()
219+ .forEach { root.append(it as Node ) }
220+
221+ // Adjust the self artifact ID, as it should match the root module's coordinates:
222+ ((root.get(" artifactId" ) as NodeList )[0 ] as Node ).setValue(artifactId)
223+
224+ // Set packaging to POM to indicate that there's no artifact:
225+ root.appendNode(" packaging" , " pom" )
226+
227+ // Remove the original platform dependencies and add a single dependency on the platform module:
228+ val dependencies = (root.get(" dependencies" ) as NodeList )[0 ] as Node
229+ dependencies.children().toList()
230+ .forEach { dependencies.remove(it as Node ) }
231+ val singleDependency = dependencies.appendNode(" dependency" )
232+ singleDependency.appendNode(
233+ " groupId" ,
234+ platformPublication.groupId
235+ )
236+ singleDependency.appendNode(
237+ " artifactId" ,
238+ platformPublication.artifactId
239+ )
240+ singleDependency.appendNode(
241+ " version" ,
242+ platformPublication.version
243+ )
244+ singleDependency.appendNode(" scope" , " compile" )
245+ }
246+ }
247+
248+ tasks.matching { it.name == " generatePomFileForKotlinMultiplatformPublication" }
249+ .configureEach {
250+ dependsOn(tasks[" generatePomFileFor${platformPublication.name.capitalize()} Publication" ])
251+ }
252+
253+ }
205254
206255// publication
207256subprojects {
257+ afterEvaluate {
208258
209- val versionSuffix: String? by project
210- if (versionSuffix != null ) {
211- project.version = project.version.toString() + versionSuffix
212- }
259+ val versionSuffix: String? by project
260+ if (versionSuffix != null ) {
261+ project.version = project.version.toString() + versionSuffix
262+ }
213263
214- plugins.withId(" org.jetbrains.kotlin.multiplatform" ) {
215- extensions.configure<KotlinMultiplatformExtension > {
216- targets.all {
217- mavenPublication {
218- pom {
219- name.set(project.name)
220- description.set(project.description)
221- url.set(" http://rsocket.io" )
222-
223- licenses {
224- license {
225- name.set(" The Apache Software License, Version 2.0" )
226- url.set(" https://www.apache.org/licenses/LICENSE-2.0.txt" )
227- distribution.set(" repo" )
264+ task<Jar >(" javadocJar" ) {
265+ archiveClassifier.set(" javadoc" )
266+ }
267+
268+ tasks.withType<Sign > {
269+ dependsOn(" javadocJar" )
270+ }
271+
272+ plugins.withId(" org.jetbrains.kotlin.multiplatform" ) {
273+ extensions.configure<KotlinMultiplatformExtension > {
274+ targets.all {
275+ mavenPublication {
276+ pom {
277+ name.set(project.name)
278+ description.set(project.description)
279+ url.set(" http://rsocket.io" )
280+
281+ licenses {
282+ license {
283+ name.set(" The Apache Software License, Version 2.0" )
284+ url.set(" https://www.apache.org/licenses/LICENSE-2.0.txt" )
285+ distribution.set(" repo" )
286+ }
228287 }
229- }
230- developers {
231- developer {
232- id.set(" whyoleg" )
233- name.set(" Oleg Yukhnevich" )
234- 288+ developers {
289+ developer {
290+ id.set(" whyoleg" )
291+ name.set(" Oleg Yukhnevich" )
292+ 293+ }
294+ developer {
295+ id.set(" OlegDokuka" )
296+ name.set(" Oleh Dokuka" )
297+ 298+ }
235299 }
236- developer {
237- id .set(" OlegDokuka " )
238- name .set(" Oleh Dokuka " )
239- email .set(" oleh.dokuka@icloud. com" )
300+ scm {
301+ connection .set(" https://github.com/rsocket/rsocket-kotlin.git " )
302+ developerConnection .set(" https://github.com/rsocket/rsocket-kotlin.git " )
303+ url .set(" https://github. com/rsocket/rsocket-kotlin " )
240304 }
241305 }
242- scm {
243- connection.set(" https://github.com/rsocket/rsocket-kotlin.git" )
244- developerConnection.set(" https://github.com/rsocket/rsocket-kotlin.git" )
245- url.set(" https://github.com/rsocket/rsocket-kotlin" )
246- }
247306 }
248307 }
249308 }
250309 }
310+
311+ tasks.withType<PublishToMavenRepository > {
312+ dependsOn(tasks.withType<Sign >())
313+ }
314+
315+ tasks.matching { it.name == " generatePomFileForKotlinMultiplatformPublication" }.configureEach {
316+ dependsOn(tasks[" generatePomFileForJvmPublication" ])
317+ }
251318 }
252319}
253320
@@ -282,14 +349,16 @@ if (bintrayUser != null && bintrayKey != null) {
282349 }
283350 }
284351 }
352+ }
285353
286- // configure bintray / maven central
287- val sonatypeUsername: String? by project
288- val sonatypePassword: String? by project
289- if (sonatypeUsername != null && sonatypePassword != null ) {
290- subprojects {
291- plugins.withType<MavenPublishPlugin > {
292- plugins.withType<SigningPlugin > {
354+ // configure bintray / maven central
355+ val sonatypeUsername: String? by project
356+ val sonatypePassword: String? by project
357+ if (sonatypeUsername != null && sonatypePassword != null ) {
358+ subprojects {
359+ afterEvaluate {
360+ plugins.withId(" maven-publish" ) {
361+ plugins.withId(" signing" ) {
293362 extensions.configure<SigningExtension > {
294363 // requiring signature if there is a publish task that is not to MavenLocal
295364 isRequired = gradle.taskGraph.allTasks.any {
@@ -303,20 +372,23 @@ if (bintrayUser != null && bintrayKey != null) {
303372 useInMemoryPgpKeys(signingKey, signingPassword)
304373 val names = publicationNames
305374 val publishing: PublishingExtension by project.extensions
306- afterEvaluate {
375+ beforeEvaluate {
307376 publishing.publications
308- .filterIsInstance<MavenPublication >()
309- .filter { it.name in names }
310- .forEach { publication ->
311- val moduleFile = buildDir.resolve(" publications/${publication.name} /module.json" )
312- if (moduleFile.exists()) {
313- publication.artifact(object : FileBasedMavenArtifact (moduleFile) {
314- override fun getDefaultExtension () = " module"
315- })
377+ .filterIsInstance<MavenPublication >()
378+ .filter { it.name in names }
379+ .forEach { publication ->
380+ val moduleFile =
381+ buildDir.resolve(" publications/${publication.name} /module.json" )
382+ if (moduleFile.exists()) {
383+ publication.artifact(object :
384+ FileBasedMavenArtifact (moduleFile) {
385+ override fun getDefaultExtension () = " module"
386+ })
387+ }
316388 }
317- sign(publication)
318- }
319-
389+ }
390+ afterEvaluate {
391+ sign( * publishing.publications.toTypedArray())
320392 }
321393 }
322394
@@ -331,6 +403,27 @@ if (bintrayUser != null && bintrayKey != null) {
331403 }
332404 }
333405 }
406+
407+ publications.filterIsInstance<MavenPublication >().forEach {
408+ // add empty javadocs
409+ if (name != " kotlinMultiplatform" ) {
410+ it.artifact(tasks[" javadocJar" ])
411+ }
412+
413+ val type = it.name
414+ when (type) {
415+ " kotlinMultiplatform" -> {
416+ // With Kotlin 1.4 & HMPP, the root module should have no suffix in the ID, but for compatibility with
417+ // the consumers who can't read Gradle module metadata, we publish the JVM artifacts in it, too
418+ it.artifactId = project.name
419+ publishPlatformArtifactsInRootModule(
420+ publications[" jvm" ] as MavenPublication ,
421+ it
422+ )
423+ }
424+ else -> it.artifactId = " ${project.name} -$type "
425+ }
426+ }
334427 }
335428 }
336429 }
0 commit comments