Add sourcesJar from metadata target to root multiplatform publication
^KT-44298 fixed
This commit is contained in:
committed by
Sebastian Sellmair
parent
dfdd107fc0
commit
bfbb6afee5
+26
@@ -266,6 +266,19 @@ class HierarchicalMppIT : BaseGradleIT() {
|
||||
|
||||
assertEquals(expectedProjectStructureMetadata, parsedProjectStructureMetadata)
|
||||
}
|
||||
|
||||
ZipFile(
|
||||
project.projectDir.parentFile.resolve(
|
||||
"repo/com/example/foo/my-lib-foo/1.0/my-lib-foo-1.0-sources.jar"
|
||||
)
|
||||
).use { publishedSourcesJar ->
|
||||
publishedSourcesJar.checkAllEntryNamesArePresent(
|
||||
"commonMain/Foo.kt",
|
||||
"jvmAndJsMain/FooJvmAndJs.kt",
|
||||
"linuxAndJsMain/FooLinuxAndJs.kt",
|
||||
"linuxX64Main/FooLinux.kt"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkMyLibBar(compiledProject: CompiledProject, subprojectPrefix: String?) = with(compiledProject) {
|
||||
@@ -305,6 +318,19 @@ class HierarchicalMppIT : BaseGradleIT() {
|
||||
assertEquals(expectedProjectStructureMetadata, parsedProjectStructureMetadata)
|
||||
}
|
||||
|
||||
ZipFile(
|
||||
project.projectDir.parentFile.resolve(
|
||||
"repo/com/example/bar/my-lib-bar/1.0/my-lib-bar-1.0-sources.jar"
|
||||
)
|
||||
).use { publishedSourcesJar ->
|
||||
publishedSourcesJar.checkAllEntryNamesArePresent(
|
||||
"commonMain/Bar.kt",
|
||||
"jvmAndJsMain/BarJvmAndJs.kt",
|
||||
"linuxAndJsMain/BarLinuxAndJs.kt",
|
||||
"linuxX64Main/BarLinux.kt"
|
||||
)
|
||||
}
|
||||
|
||||
checkNamesOnCompileClasspath(
|
||||
"$taskPrefix:compileKotlinMetadata",
|
||||
shouldInclude = listOf(
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@file:Suppress("FunctionName")
|
||||
|
||||
package org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.gradle.api.internal.project.ProjectInternal
|
||||
import org.gradle.api.publish.PublishingExtension
|
||||
import org.gradle.api.publish.maven.MavenPublication
|
||||
import org.gradle.testfixtures.ProjectBuilder
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertTrue
|
||||
import kotlin.test.fail
|
||||
|
||||
class MppPublicationTest {
|
||||
|
||||
private val project = ProjectBuilder.builder().build() as ProjectInternal
|
||||
|
||||
init {
|
||||
project.plugins.apply("kotlin-multiplatform")
|
||||
project.plugins.apply("maven-publish")
|
||||
}
|
||||
|
||||
private val kotlin = project.extensions.getByType(KotlinMultiplatformExtension::class.java)
|
||||
|
||||
init {
|
||||
kotlin.jvm()
|
||||
kotlin.js().nodejs()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `contains kotlinMultiplatform publication`() {
|
||||
project.evaluate()
|
||||
val publishing = project.extensions.getByType(PublishingExtension::class.java)
|
||||
publishing.publications
|
||||
.withType(MavenPublication::class.java)
|
||||
.findByName("kotlinMultiplatform") ?: fail("Missing 'kotlinMultiplatform' publication")
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun `all publication contains sourcesJar`() {
|
||||
project.evaluate()
|
||||
val publishing = project.extensions.getByType(PublishingExtension::class.java)
|
||||
publishing.publications
|
||||
.filterIsInstance<MavenPublication>()
|
||||
.forEach { publication ->
|
||||
val sources = publication.artifacts.filter { artifact -> artifact.classifier == "sources" }
|
||||
assertTrue(sources.isNotEmpty(), "Expected at least one sources artifact for ${publication.name}")
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-2
@@ -203,6 +203,7 @@ class KotlinMultiplatformPlugin(
|
||||
private fun configurePublishingWithMavenPublish(project: Project) = project.pluginManager.withPlugin("maven-publish") { _ ->
|
||||
|
||||
val targets = project.multiplatformExtension.targets
|
||||
val metadataTarget = project.multiplatformExtension.metadata()
|
||||
val kotlinSoftwareComponent = project.multiplatformExtension.rootSoftwareComponent
|
||||
|
||||
project.extensions.configure(PublishingExtension::class.java) { publishing ->
|
||||
@@ -213,12 +214,19 @@ class KotlinMultiplatformPlugin(
|
||||
(this as MavenPublicationInternal).publishWithOriginalFileName()
|
||||
kotlinSoftwareComponent.publicationDelegate = this@apply
|
||||
|
||||
project.multiplatformExtension.metadata {}.kotlinComponents.filterIsInstance<KotlinTargetComponentWithPublication>()
|
||||
metadataTarget.kotlinComponents.filterIsInstance<KotlinTargetComponentWithPublication>()
|
||||
.single().publicationDelegate = this@apply
|
||||
|
||||
project.whenEvaluated {
|
||||
if (!metadataTarget.publishable) return@whenEvaluated
|
||||
metadataTarget.kotlinComponents
|
||||
.flatMap { component -> component.sourcesArtifacts }
|
||||
.forEach { sourcesArtifact -> artifact(sourcesArtifact) }
|
||||
}
|
||||
}
|
||||
|
||||
// Enforce the order of creating the publications, since the metadata publication is used in the other publications:
|
||||
(targets.getByName(METADATA_TARGET_NAME) as AbstractKotlinTarget).createMavenPublications(publishing.publications)
|
||||
metadataTarget.createMavenPublications(publishing.publications)
|
||||
targets
|
||||
.withType(AbstractKotlinTarget::class.java).matching { it.publishable && it.name != METADATA_TARGET_NAME }
|
||||
.all {
|
||||
|
||||
Reference in New Issue
Block a user