[MPP] Fix warning reports for subprojects

Properly report warnings for projects that don't apply multiplatform
plugin in the root project, but declare the obsolete properties

KT-55891
This commit is contained in:
Pavel Kirpichenkov
2023-01-26 20:48:37 +02:00
committed by Space Team
parent b0c360b1b6
commit a03db78ed2
2 changed files with 13 additions and 2 deletions
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.gradle.mpp
import org.gradle.util.GradleVersion import org.gradle.util.GradleVersion
import org.jetbrains.kotlin.gradle.testbase.* import org.jetbrains.kotlin.gradle.testbase.*
import kotlin.io.path.appendText import kotlin.io.path.appendText
import kotlin.io.path.writeText
import kotlin.test.assertFalse import kotlin.test.assertFalse
import kotlin.test.assertTrue import kotlin.test.assertTrue
@@ -27,6 +28,10 @@ class MppDeprecatedPropertiesIt : KGPBaseTest() {
) )
checkDeprecations(isDeprecationExpected = true) checkDeprecations(isDeprecationExpected = true)
// remove the MPP plugin from the top-level project and check the warnings are still reported in subproject
this.buildGradleKts.writeText("")
checkDeprecations(isDeprecationExpected = true)
this.gradleProperties.appendText("kotlin.mpp.deprecatedProperties.nowarn=true${System.lineSeparator()}") this.gradleProperties.appendText("kotlin.mpp.deprecatedProperties.nowarn=true${System.lineSeparator()}")
checkDeprecations(isDeprecationExpected = false) checkDeprecations(isDeprecationExpected = false)
} }
@@ -38,12 +38,13 @@ internal fun checkAndReportDeprecatedNativeTargets(project: Project) {
* Warnings have to be reported only for successfully evaluated projects without errors. * Warnings have to be reported only for successfully evaluated projects without errors.
*/ */
internal fun checkAndReportDeprecatedMppProperties(project: Project) { internal fun checkAndReportDeprecatedMppProperties(project: Project) {
if (project !== project.rootProject) return
val projectProperties = project.kotlinPropertiesProvider val projectProperties = project.kotlinPropertiesProvider
if (projectProperties.ignoreHmppDeprecationWarnings == true) return if (projectProperties.ignoreHmppDeprecationWarnings == true) return
val warnings = deprecatedMppProperties.mapNotNull { propertyName -> val warnings = deprecatedMppProperties.mapNotNull { propertyName ->
if (propertyName in propertiesSetByPlugin && projectProperties.mpp13XFlagsSetByPlugin)
return@mapNotNull null
@OptIn(UnsafeApi::class) @OptIn(UnsafeApi::class)
projectProperties.property(propertyName)?.let { getMppDeprecationWarningMessageForProperty(propertyName) } projectProperties.property(propertyName)?.let { getMppDeprecationWarningMessageForProperty(propertyName) }
} }
@@ -65,6 +66,11 @@ internal val deprecatedMppProperties: List<String> = listOf(
KOTLIN_NATIVE_DEPENDENCY_PROPAGATION, KOTLIN_NATIVE_DEPENDENCY_PROPAGATION,
) )
private val propertiesSetByPlugin: Set<String> = setOf(
KOTLIN_MPP_ENABLE_GRANULAR_SOURCE_SETS_METADATA,
KOTLIN_NATIVE_DEPENDENCY_PROPAGATION,
)
internal fun getMppDeprecationWarningMessageForProperty(property: String): String = internal fun getMppDeprecationWarningMessageForProperty(property: String): String =
"w: The property '$property' is obsolete and will be removed in Kotlin 1.9. Read the details here: " + "w: The property '$property' is obsolete and will be removed in Kotlin 1.9. Read the details here: " +
"https://kotlinlang.org/docs/multiplatform-compatibility-guide.html#deprecate-hmpp-properties" "https://kotlinlang.org/docs/multiplatform-compatibility-guide.html#deprecate-hmpp-properties"