Fixes for new MPP publishing
* Generate the JARs with the same names as they are published. Put the target name in the JAR name's appendix instead of classifier. * Configure Maven publications eagerly to allow their editing by user. * Take KotlinVariant's coordinates from the MavenPublication. If the user changes Maven coordinates of the publication, this ensures the parent component to have the updated information.
This commit is contained in:
committed by
Ilya Matveev
parent
440f6996d2
commit
36a81acb5d
+4
-4
@@ -46,9 +46,9 @@ class NewMultiplatformIT : BaseGradleIT() {
|
||||
assertTasksExecuted(*compileTasksNames.toTypedArray(), ":jvm6Jar", ":nodeJsJar", ":metadataJar")
|
||||
|
||||
val groupDir = projectDir.resolve("repo/com/example")
|
||||
val jvmJarName = "sample-lib-jvm6/1.0/sample-lib-jvm6-1.0-jvm6.jar"
|
||||
val jsJarName = "sample-lib-nodejs/1.0/sample-lib-nodejs-1.0-nodeJs.jar"
|
||||
val metadataJarName = "sample-lib-metadata/1.0/sample-lib-metadata-1.0-metadata.jar"
|
||||
val jvmJarName = "sample-lib-jvm6/1.0/sample-lib-jvm6-1.0.jar"
|
||||
val jsJarName = "sample-lib-nodejs/1.0/sample-lib-nodejs-1.0.jar"
|
||||
val metadataJarName = "sample-lib-metadata/1.0/sample-lib-metadata-1.0.jar"
|
||||
val wasmKlibName = "sample-lib-wasm32/1.0/sample-lib-wasm32-1.0.klib"
|
||||
val nativeKlibName = "sample-lib-$hostTargetName/1.0/sample-lib-$hostTargetName-1.0.klib"
|
||||
|
||||
@@ -383,7 +383,7 @@ class NewMultiplatformIT : BaseGradleIT() {
|
||||
build("printMetadataFiles") {
|
||||
assertSuccessful()
|
||||
|
||||
val expectedFileName = "sample-lib-1.0-${KotlinMultiplatformPlugin.METADATA_TARGET_NAME}.jar"
|
||||
val expectedFileName = "sample-lib-${KotlinMultiplatformPlugin.METADATA_TARGET_NAME}-1.0.jar"
|
||||
|
||||
val paths = metadataDependencyRegex.findAll(output).map { it.groupValues[1] to it.groupValues[2] }.toSet()
|
||||
|
||||
|
||||
+1
-1
@@ -341,7 +341,7 @@ open class KotlinTargetConfigurator<KotlinCompilationType: KotlinCompilation>(
|
||||
|
||||
val apiElementsConfiguration = project.configurations.getByName(target.apiElementsConfigurationName)
|
||||
|
||||
target.disambiguationClassifier?.let { jar.classifier = it }
|
||||
target.disambiguationClassifier?.let { jar.appendix = it.toLowerCase() }
|
||||
|
||||
// Workaround: adding the artifact during configuration seems to interfere with the Java plugin, which results into missing
|
||||
// task dependency 'assemble -> jar' if the Java plugin is applied after this steps
|
||||
|
||||
+23
-19
@@ -94,29 +94,33 @@ class KotlinMultiplatformPlugin(
|
||||
val targets = project.multiplatformExtension!!.targets
|
||||
val kotlinSoftwareComponent = KotlinSoftwareComponent(project, "kotlin", targets)
|
||||
|
||||
project.afterEvaluate { project -> // Use afterEvaluate because publications configuration is no more lazy since Gradle 4.9
|
||||
project.extensions.configure(PublishingExtension::class.java) { publishing ->
|
||||
// The root publication.
|
||||
publishing.publications.create("kotlin", MavenPublication::class.java) { publication ->
|
||||
publication.from(kotlinSoftwareComponent)
|
||||
(publication as MavenPublicationInternal).publishWithOriginalFileName()
|
||||
publication.artifactId = project.name
|
||||
publication.groupId = project.group.toString()
|
||||
}
|
||||
project.extensions.configure(PublishingExtension::class.java) { publishing ->
|
||||
// The root publication.
|
||||
publishing.publications.create("kotlinMultiplatform", MavenPublication::class.java).apply {
|
||||
from(kotlinSoftwareComponent)
|
||||
(this as MavenPublicationInternal).publishWithOriginalFileName()
|
||||
artifactId = project.name
|
||||
groupId = project.group.toString()
|
||||
version = project.version.toString()
|
||||
}
|
||||
|
||||
// Create separate publications for all publishable targets
|
||||
kotlinSoftwareComponent.variants.filter { it.publishable }.forEach { variant ->
|
||||
val coordinates = (variant as? KotlinVariantWithCoordinates)?.coordinates
|
||||
val name = variant.target.disambiguateName("kotlin")
|
||||
// Create separate publications for all publishable targets
|
||||
targets.matching { it.publishable }.all { target ->
|
||||
val variant = target.component as KotlinVariant
|
||||
val name = target.name
|
||||
|
||||
publishing.publications.create(name, MavenPublication::class.java) { publication ->
|
||||
publication.from(variant)
|
||||
(publication as MavenPublicationInternal).publishWithOriginalFileName()
|
||||
publication.artifactId = coordinates?.name ?: "${project.name}-${variant.target.name.toLowerCase()}"
|
||||
publication.groupId = coordinates?.group ?: project.group.toString()
|
||||
publication.version = coordinates?.version ?: project.version.toString()
|
||||
val variantPublication = publishing.publications.create(name, MavenPublication::class.java).apply {
|
||||
// do this in afterEvaluate since older Gradle versions seem to check the files in the variant eagerly:
|
||||
project.afterEvaluate {
|
||||
from(variant)
|
||||
}
|
||||
(this as MavenPublicationInternal).publishWithOriginalFileName()
|
||||
artifactId = "${project.name}-${variant.target.name.toLowerCase()}"
|
||||
groupId = project.group.toString()
|
||||
version = project.version.toString()
|
||||
}
|
||||
|
||||
variant.publicationDelegate = variantPublication
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+13
-3
@@ -14,6 +14,7 @@ import org.gradle.api.component.ComponentWithCoordinates
|
||||
import org.gradle.api.component.ComponentWithVariants
|
||||
import org.gradle.api.internal.component.SoftwareComponentInternal
|
||||
import org.gradle.api.internal.component.UsageContext
|
||||
import org.gradle.api.publish.maven.MavenPublication
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetComponent
|
||||
import org.jetbrains.kotlin.gradle.plugin.usageByName
|
||||
@@ -43,6 +44,10 @@ open class KotlinVariant(
|
||||
override fun getUsages(): Set<UsageContext> = target.createUsageContexts()
|
||||
override fun getName(): String = target.name
|
||||
|
||||
// This property is declared in the parent class to allow usages to reference it without forcing the subclass to load,
|
||||
// which is needed for compatibility with older Gradle versions
|
||||
internal var publicationDelegate: MavenPublication? = null
|
||||
|
||||
override val publishable: Boolean
|
||||
get() = target.publishable
|
||||
}
|
||||
@@ -55,12 +60,17 @@ class KotlinVariantWithCoordinates(
|
||||
override fun getCoordinates() = object : ModuleVersionIdentifier {
|
||||
private val project get() = target.project
|
||||
|
||||
private val moduleName: String get() = "${project.name}-${target.name.toLowerCase()}"
|
||||
private val moduleGroup: String get() = project.group.toString()
|
||||
private val moduleName: String get() =
|
||||
publicationDelegate?.artifactId ?:
|
||||
"${project.name}-${target.name.toLowerCase()}"
|
||||
|
||||
private val moduleGroup: String get() =
|
||||
publicationDelegate?.groupId ?:
|
||||
project.group.toString()
|
||||
|
||||
override fun getGroup() = moduleGroup
|
||||
override fun getName() = moduleName
|
||||
override fun getVersion() = project.version.toString()
|
||||
override fun getVersion() = publicationDelegate?.version ?: project.version.toString()
|
||||
|
||||
override fun getModule(): ModuleIdentifier = object : ModuleIdentifier {
|
||||
override fun getGroup(): String = moduleGroup
|
||||
|
||||
Reference in New Issue
Block a user