[mpp] Don't report kotlin-test as pre-HMPP dependency

- Exclude kotlin-stdlib and kotlin-test from reporting

- kotlin-stdlib wasn't reported, because it doesn't even have Gradle
modular metadata (so no o.j.k.platform.type attribute, and check doesn't
work). This commit explicitly excludes kotlin-stdlib, so that when it
starts publishing Gradle Modular Metadata, nothing would break

- kotlin-test was reported only when it is declared in commonMain,
because we're checking only metadata compilations, and commonTest
isn't compiled to metadata

- Depending on kotlin-test is an odd configuration, but it arises
sometimes (e.g. when people extract some test utilities in a separate
Gradle project)

^KT-58872
This commit is contained in:
Dmitry Savvinov
2023-07-26 12:40:18 +02:00
committed by Space Team
parent 14b340c61e
commit 38cd8ee7e7
3 changed files with 38 additions and 0 deletions
@@ -60,6 +60,11 @@ class PreHmppDependenciesDeprecationIT : KGPBaseTest() {
checkDiagnostics(gradleVersion, "noWarningsOnPopularDependencies")
}
@GradleTest
fun testNoWarningsOnKotlinTestIfAddedInCommonMain(gradleVersion: GradleVersion) {
checkDiagnostics(gradleVersion, "noWarningsOnKotlinTestIfAddedInCommonMain")
}
@GradleTest
fun testNoWarningsOnProjectDependencies(gradleVersion: GradleVersion) {
checkDiagnostics(gradleVersion, "noWarningsOnProjectDependencies", projectPathToCheck = ":consumer")
@@ -0,0 +1,23 @@
plugins {
kotlin("multiplatform")
}
repositories {
mavenCentral()
mavenLocal()
maven("<localRepo>")
}
kotlin {
jvm() {
}
linuxX64()
sourceSets.getByName("commonMain").dependencies {
implementation(kotlin("test"))
}
sourceSets.getByName("jvmMain").dependencies {
implementation(kotlin("test-junit"))
}
}
@@ -72,6 +72,7 @@ internal object PreHmppDependenciesUsageChecker : KotlinGradleProjectChecker {
}
private fun isPreHmppDependency(dependency: ResolvedDependencyResult): Boolean {
if (isAllowedDependency(dependency.selected.id)) return false
val attributes = dependency.resolvedVariant.attributes
val kotlinPlatformAttribute = attributes.getAttribute(Attribute.of(KotlinPlatformType.attribute.name, String::class.java))
?: return false
@@ -79,4 +80,13 @@ internal object PreHmppDependenciesUsageChecker : KotlinGradleProjectChecker {
return kotlinPlatformAttribute == KotlinPlatformType.common.name && usageAttribute != KotlinUsages.KOTLIN_METADATA
}
private fun isAllowedDependency(identifier: ComponentIdentifier): Boolean {
return when {
identifier !is ModuleComponentIdentifier -> false
identifier.group != "org.jetbrains.kotlin" -> false
identifier.module.contains("kotlin-stdlib") || identifier.module.contains("kotlin-test") -> true
else -> false
}
}
}