Deprecate kotlin.mpp.androidSourceSetLayoutVersion=1

^KT-58489
This commit is contained in:
Timofey Solonin
2023-07-27 09:28:48 +02:00
committed by Space Team
parent 2eba7da5eb
commit 6d9b34ab46
13 changed files with 39 additions and 35 deletions
@@ -1 +0,0 @@
kotlin.mpp.androidSourceSetLayoutVersion=1
@@ -1,4 +1 @@
kotlin.code.style=official
# Test is about compatibility, only version 1 was available in previous versions
kotlin.mpp.androidSourceSetLayoutVersion=1
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLI
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ANDROID_GRADLE_PLUGIN_COMPATIBILITY_NO_WARN
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ANDROID_SOURCE_SET_LAYOUT_ANDROID_STYLE_NO_WARN
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ANDROID_SOURCE_SET_LAYOUT_VERSION
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ANDROID_SOURCE_SET_LAYOUT_VERSION_1_NO_WARN
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_APPLY_DEFAULT_HIERARCHY_TEMPLATE
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_DEPRECATED_PROPERTIES_NO_WARN
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ENABLE_CINTEROP_COMMONIZATION
@@ -254,9 +253,6 @@ internal class PropertiesProvider private constructor(private val project: Proje
val mppAndroidSourceSetLayoutVersion: Int?
get() = this.property(KOTLIN_MPP_ANDROID_SOURCE_SET_LAYOUT_VERSION)?.toIntOrNull()
val ignoreMppAndroidSourceSetLayoutVersion: Boolean
get() = booleanProperty(KOTLIN_MPP_ANDROID_SOURCE_SET_LAYOUT_VERSION_1_NO_WARN) ?: false
val ignoreMppAndroidSourceSetLayoutV2AndroidStyleDirs: Boolean
get() = booleanProperty(KOTLIN_MPP_ANDROID_SOURCE_SET_LAYOUT_ANDROID_STYLE_NO_WARN) ?: false
@@ -595,7 +591,6 @@ internal class PropertiesProvider private constructor(private val project: Proje
const val KOTLIN_MPP_DEPRECATED_PROPERTIES_NO_WARN = "kotlin.mpp.deprecatedProperties.nowarn"
const val KOTLIN_MPP_ANDROID_GRADLE_PLUGIN_COMPATIBILITY_NO_WARN = "kotlin.mpp.androidGradlePluginCompatibility.nowarn"
const val KOTLIN_MPP_ANDROID_SOURCE_SET_LAYOUT_VERSION = "kotlin.mpp.androidSourceSetLayoutVersion"
const val KOTLIN_MPP_ANDROID_SOURCE_SET_LAYOUT_VERSION_1_NO_WARN = "${KOTLIN_MPP_ANDROID_SOURCE_SET_LAYOUT_VERSION}1.nowarn"
const val KOTLIN_MPP_ANDROID_SOURCE_SET_LAYOUT_ANDROID_STYLE_NO_WARN = "kotlin.mpp.androidSourceSetLayoutV2AndroidStyleDirs.nowarn"
const val KOTLIN_MPP_IMPORT_ENABLE_KGP_DEPENDENCY_RESOLUTION = "kotlin.mpp.import.enableKgpDependencyResolution"
const val KOTLIN_MPP_IMPORT_ENABLE_SLOW_SOURCES_JAR_RESOLVER = "kotlin.mpp.import.enableSlowSourcesJarResolver"
@@ -87,17 +87,12 @@ object KotlinToolingDiagnostics {
}
}
object PromoteAndroidSourceSetLayoutV2Warning : ToolingDiagnosticFactory(WARNING) {
object AndroidSourceSetLayoutV1Deprecation : ToolingDiagnosticFactory(ERROR) {
operator fun invoke() = build(
"""
${multiplatformAndroidSourceSetLayoutV1.name} is deprecated. Use ${multiplatformAndroidSourceSetLayoutV2.name} instead.
To enable ${multiplatformAndroidSourceSetLayoutV2.name}: put the following in your gradle.properties:
${PropertiesProvider.PropertyNames.KOTLIN_MPP_ANDROID_SOURCE_SET_LAYOUT_VERSION}=2
The version 1 of Android source set layout is deprecated. Please remove kotlin.mpp.androidSourceSetLayoutVersion=1 from the gradle.properties file.
To suppress this warning: put the following in your gradle.properties:
${PropertiesProvider.PropertyNames.KOTLIN_MPP_ANDROID_SOURCE_SET_LAYOUT_VERSION_1_NO_WARN}=true
Learn more: https://kotlinlang.org/docs/whatsnew18.html#kotlin-multiplatform-a-new-android-source-set-layout
Learn how to migrate to the version 2 source set layout at: https://kotl.in/android-source-set-layout-v2
""".trimIndent()
)
}
@@ -120,7 +115,7 @@ object KotlinToolingDiagnostics {
To suppress this warning: put the following in your gradle.properties:
${PropertiesProvider.PropertyNames.KOTLIN_MPP_ANDROID_SOURCE_SET_LAYOUT_ANDROID_STYLE_NO_WARN}=true
Learn more: https://kotlinlang.org/docs/whatsnew18.html#kotlin-multiplatform-a-new-android-source-set-layout
Learn more: https://kotl.in/android-source-set-layout-v2
""".trimIndent()
)
}
@@ -181,7 +176,7 @@ object KotlinToolingDiagnostics {
sourceSets.getByName("androidAndroidTest") -> sourceSets.getByName("androidInstrumentedTest")
Learn more about the new Kotlin/Android SourceSet Layout:
https://kotlinlang.org/docs/whatsnew18.html#kotlin-multiplatform-a-new-android-source-set-layout
https://kotl.in/android-source-set-layout-v2
""".trimIndent()
)
}
@@ -48,7 +48,7 @@ internal val multiplatformAndroidSourceSetLayoutV1 = KotlinAndroidSourceSetLayou
MultiplatformLayoutV1SourceDirConfigurator
),
checker = KotlinAndroidSourceSetLayoutChecker(
MultiplatformLayoutV1PromoteV2Checker
MultiplatformLayoutV1DeprecationChecker
)
)
@@ -60,7 +60,8 @@ internal val multiplatformAndroidSourceSetLayoutV2 = KotlinAndroidSourceSetLayou
AndroidKaptSourceSetConfigurator,
MultiplatformAndroidResourceDirConfigurator,
MultiplatformLayoutV2DependsOnConfigurator,
Agp7AddKotlinSourcesToAndroidSourceSetConfigurator,
Agp7AddKotlinSourcesToAndroidSourceSetConfigurator
.onlyIf { AndroidGradlePluginVersion.current >= "7.0.0" },
MultiplatformLayoutV2SourceDirConfigurator,
MultiplatformLayoutV2DefaultManifestLocationConfigurator
),
@@ -5,28 +5,22 @@
package org.jetbrains.kotlin.gradle.plugin.sources.android.checker
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinToolingDiagnostics
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinToolingDiagnosticsCollector
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
import org.jetbrains.kotlin.gradle.plugin.sources.android.KotlinAndroidSourceSetLayout
/**
* Promotes MultiplatformAndroidSourceSetLayoutV2 when requirements are met
* Emits a deprecation error
*/
internal object MultiplatformLayoutV1PromoteV2Checker : KotlinAndroidSourceSetLayoutChecker {
internal object MultiplatformLayoutV1DeprecationChecker : KotlinAndroidSourceSetLayoutChecker {
override fun checkBeforeLayoutApplied(
diagnosticsCollector: KotlinToolingDiagnosticsCollector,
target: KotlinAndroidTarget,
layout: KotlinAndroidSourceSetLayout
) {
if (target.project.kotlinPropertiesProvider.ignoreMppAndroidSourceSetLayoutVersion) return
runCatching {
if (MultiplatformLayoutV2AgpRequirementChecker.isAgpRequirementMet()) {
diagnosticsCollector.reportOncePerGradleBuild(
target.project, KotlinToolingDiagnostics.PromoteAndroidSourceSetLayoutV2Warning()
)
}
}
diagnosticsCollector.reportOncePerGradleBuild(
target.project, KotlinToolingDiagnostics.AndroidSourceSetLayoutV1Deprecation()
)
}
}
@@ -16,8 +16,11 @@ import org.gradle.testfixtures.ProjectBuilder
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
import org.jetbrains.kotlin.gradle.plugin.extraProperties
import org.jetbrains.kotlin.gradle.plugin.sources.android.findKotlinSourceSet
import org.jetbrains.kotlin.gradle.util.addBuildEventsListenerRegistryMock
import org.jetbrains.kotlin.gradle.util.checkDiagnostics
import org.jetbrains.kotlin.gradle.util.setMultiplatformAndroidSourceSetLayoutVersion
import kotlin.test.*
@@ -44,6 +47,12 @@ class MultiplatformAndroidSourceSetLayoutV1Test {
kotlin = project.multiplatformExtension
}
@Test
fun `version 1 layout usage - emits a deprecation error`() {
kotlin.androidTarget()
project.evaluate()
project.checkDiagnostics("AndroidSourceSetV1Deprecation")
}
@Test
fun `main source set with default settings`() {
@@ -0,0 +1,14 @@
[AndroidSourceSetLayoutV1Deprecation | ERROR] The version 1 of Android source set layout is deprecated. Please remove kotlin.mpp.androidSourceSetLayoutVersion=1 from the gradle.properties file.
Learn how to migrate to the version 2 source set layout at: https://kotl.in/android-source-set-layout-v2
----
[KotlinDefaultHierarchyFallbackDependsOnUsageDetected | WARNING] The Default Kotlin Hierarchy was not applied to 'root project 'test'':
Manual .dependsOn() edges were configured for the following source sets:
[androidAndroidTest, androidMain, androidTest]
To suppress the 'Default Hierarchy Template' add
'kotlin.mpp.applyDefaultHierarchyTemplate=false'
to your gradle.properties
----
[KotlinSourceSetTreeDependsOnMismatch | WARNING] Kotlin Source Set 'androidAndroidTest' can't depend on 'commonTest' as they are from different Source Set Trees.
Please remove this dependency edge.
@@ -4,7 +4,7 @@ Use src/androidMain/kotlin instead.
To suppress this warning: put the following in your gradle.properties:
kotlin.mpp.androidSourceSetLayoutV2AndroidStyleDirs.nowarn=true
Learn more: https://kotlinlang.org/docs/whatsnew18.html#kotlin-multiplatform-a-new-android-source-set-layout
Learn more: https://kotl.in/android-source-set-layout-v2
----
[AndroidStyleSourceDirUsageWarning | WARNING] Usage of 'Android Style' source directory src/test/kotlin is deprecated.
Use src/androidUnitTest/kotlin instead.
@@ -12,4 +12,4 @@ Use src/androidUnitTest/kotlin instead.
To suppress this warning: put the following in your gradle.properties:
kotlin.mpp.androidSourceSetLayoutV2AndroidStyleDirs.nowarn=true
Learn more: https://kotlinlang.org/docs/whatsnew18.html#kotlin-multiplatform-a-new-android-source-set-layout
Learn more: https://kotl.in/android-source-set-layout-v2
@@ -4,4 +4,4 @@ Use src/androidInstrumentedTest/kotlin instead.
To suppress this warning: put the following in your gradle.properties:
kotlin.mpp.androidSourceSetLayoutV2AndroidStyleDirs.nowarn=true
Learn more: https://kotlinlang.org/docs/whatsnew18.html#kotlin-multiplatform-a-new-android-source-set-layout
Learn more: https://kotl.in/android-source-set-layout-v2