[Gradle/MPP] Deprecated android in favour androidTarget in MPP DSL

ReplaceWith was added only to `android()` and `android(name)`
because it isn't working for other functions: KTIJ-25383.

#KT-57903 In Progress
This commit is contained in:
Stanislav Erokhin
2023-04-25 11:27:51 +02:00
committed by Space Team
parent becf50ee0f
commit 70c9d6dc44
2 changed files with 42 additions and 1 deletions
@@ -219,3 +219,19 @@ internal fun <T : KotlinTarget> KotlinTargetsContainerWithPresets.configureOrCre
}
}
}
internal fun KotlinTargetsContainerWithPresets.configureOrCreateAndroidTargetAndReportDeprecation(
targetName: String,
configure: KotlinAndroidTarget.() -> Unit
): KotlinAndroidTarget {
val targetPreset = presets.getByName("android") as KotlinAndroidTargetPreset
val result = configureOrCreate(targetName, targetPreset, configure)
result.project.logger.warn(
"""
w: Please use `androidTarget` function instead of `android` to configure android target inside `kotlin { }` block.
See the details here: https://kotl.in/android-target-dsl
""".trimIndent()
)
return result
}
@@ -10,9 +10,11 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinTargetsContainerWithPresets
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTargetPreset
private const val ANDROID_TARGET_MIGRATION_MESSAGE = "Please use androidTarget() instead. Learn more here: https://kotl.in/android-target-dsl"
interface KotlinTargetContainerWithAndroidPresetFunctions : KotlinTargetsContainerWithPresets {
fun android(
fun androidTarget(
name: String = "android",
configure: KotlinAndroidTarget.() -> Unit = { }
): KotlinAndroidTarget =
@@ -22,9 +24,32 @@ interface KotlinTargetContainerWithAndroidPresetFunctions : KotlinTargetsContain
configure
)
fun androidTarget() = androidTarget("android") { }
fun androidTarget(name: String) = androidTarget(name) { }
fun androidTarget(name: String, configure: Action<KotlinAndroidTarget>) = androidTarget(name) { configure.execute(this) }
fun androidTarget(configure: Action<KotlinAndroidTarget>) = androidTarget { configure.execute(this) }
@Deprecated(ANDROID_TARGET_MIGRATION_MESSAGE)
fun android(
name: String = "android",
configure: KotlinAndroidTarget.() -> Unit = { }
): KotlinAndroidTarget =
configureOrCreateAndroidTargetAndReportDeprecation(name, configure)
@Suppress("DEPRECATION")
@Deprecated(ANDROID_TARGET_MIGRATION_MESSAGE, replaceWith = ReplaceWith("androidTarget()"))
fun android() = android("android") { }
@Suppress("DEPRECATION")
@Deprecated(ANDROID_TARGET_MIGRATION_MESSAGE, replaceWith = ReplaceWith("androidTarget(name)"))
fun android(name: String) = android(name) { }
@Suppress("DEPRECATION")
@Deprecated(ANDROID_TARGET_MIGRATION_MESSAGE)
fun android(name: String, configure: Action<KotlinAndroidTarget>) = android(name) { configure.execute(this) }
@Suppress("DEPRECATION")
@Deprecated(ANDROID_TARGET_MIGRATION_MESSAGE)
fun android(configure: Action<KotlinAndroidTarget>) = android { configure.execute(this) }
}