Add an experimental feature warnings on MPP usage & metadata publishing

Issue #KT-25200 Fixed
This commit is contained in:
Sergey Igushkin
2018-09-21 20:03:25 +03:00
parent 54988932a3
commit 4f650bb056
3 changed files with 39 additions and 0 deletions
@@ -18,4 +18,5 @@ open class KotlinMultiplatformExtension : KotlinProjectExtension() {
internal set
internal var isGradleMetadataAvailable: Boolean = false
internal var isGradleMetadataExperimental: Boolean = false
}
@@ -26,6 +26,7 @@ import org.gradle.util.ConfigureUtil
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.gradle.utils.SingleWarningPerBuild
import org.jetbrains.kotlin.konan.target.HostManager
import org.jetbrains.kotlin.konan.target.presetName
@@ -55,6 +56,7 @@ class KotlinMultiplatformPlugin(
override fun apply(project: Project) {
project.plugins.apply(JavaBasePlugin::class.java)
SingleWarningPerBuild.show(project, "Kotlin Multiplatform Projects are an experimental feature.")
val targetsContainer = project.container(KotlinTarget::class.java)
val targetsFromPreset = TargetFromPresetExtension(targetsContainer)
@@ -70,6 +72,7 @@ class KotlinMultiplatformPlugin(
isGradleMetadataAvailable =
featurePreviews.activeFeatures.find { it.name == "GRADLE_METADATA" }?.let { metadataFeature ->
isGradleMetadataExperimental = true
featurePreviews.isFeatureEnabled(metadataFeature)
} ?: true // the feature entry will be gone once the feature is stable
}
@@ -102,6 +105,14 @@ class KotlinMultiplatformPlugin(
}
private fun configurePublishingWithMavenPublish(project: Project) = project.pluginManager.withPlugin("maven-publish") { _ ->
if (project.multiplatformExtension!!.run { isGradleMetadataAvailable && isGradleMetadataExperimental }) {
SingleWarningPerBuild.show(
project,
GRADLE_METADATA_WARNING
)
}
val targets = project.multiplatformExtension!!.targets
val kotlinSoftwareComponent = KotlinSoftwareComponent(project, "kotlin", targets)
@@ -233,6 +244,13 @@ class KotlinMultiplatformPlugin(
companion object {
const val METADATA_TARGET_NAME = "metadata"
const val GRADLE_METADATA_WARNING =
// TODO point the user to some MPP docs explaining this in more detail
"This build is set up to publish Kotlin multiplatform libraries with experimental Gradle metadata. " +
"Future Gradle versions may fail to resolve dependencies on these publications. " +
"You can disable Gradle metadata usage during publishing and dependencies resolution by removing " +
"`enableFeaturePreview('GRADLE_METADATA')` from the settings.gradle file."
}
}
@@ -0,0 +1,20 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.gradle.utils
import org.gradle.api.Project
import java.util.*
internal object SingleWarningPerBuild {
private val rootModuleReceivedWarning = WeakHashMap<Project, MutableSet<String>>()
fun show(project: Project, warningText: String) {
val receivedWarnings = rootModuleReceivedWarning.computeIfAbsent(project.rootProject) { mutableSetOf() }
if (receivedWarnings.add(warningText)) {
project.logger.warn(warningText)
}
}
}