[Gradle] Remove TargetsNeedDisambiguation diagnostic
It is overlapping with KotlinTargetAlreadyDeclared which is stricter and recommends users to migrate away from multiple target set up at all. ^KT-59316 Verification Pending
This commit is contained in:
committed by
Space Team
parent
b08d12e477
commit
bb7e738b9e
-1
@@ -102,7 +102,6 @@ internal interface KotlinGradleProjectChecker {
|
||||
MissingNativeStdlibChecker,
|
||||
UnusedSourceSetsChecker,
|
||||
AndroidSourceSetLayoutV1SourceSetsNotFoundChecker,
|
||||
TargetsWithAmbiguousConsumableConfigurationsChecker,
|
||||
AndroidPluginWithoutAndroidTargetChecker,
|
||||
NoKotlinTargetsDeclaredChecker,
|
||||
DisabledCinteropCommonizationInHmppProjectChecker,
|
||||
|
||||
-11
@@ -194,17 +194,6 @@ object KotlinToolingDiagnostics {
|
||||
)
|
||||
}
|
||||
|
||||
object TargetsNeedDisambiguation : ToolingDiagnosticFactory(WARNING) {
|
||||
operator fun invoke(targetGroupsRendered: String) = build(
|
||||
"""
|
||||
|The following targets are not distinguishable:
|
||||
|$targetGroupsRendered
|
||||
|Use an additional attribute to disambiguate them
|
||||
|See https://kotlinlang.org/docs/multiplatform-set-up-targets.html#distinguish-several-targets-for-one-platform for more details
|
||||
""".trimMargin()
|
||||
)
|
||||
}
|
||||
|
||||
object DeprecatedPropertyWithReplacement : ToolingDiagnosticFactory(WARNING) {
|
||||
operator fun invoke(deprecatedPropertyName: String, replacement: String) = build(
|
||||
"Project property '$deprecatedPropertyName' is deprecated. Please use '$replacement' instead."
|
||||
|
||||
-44
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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.plugin.diagnostics.checkers
|
||||
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginLifecycle
|
||||
import org.jetbrains.kotlin.gradle.plugin.await
|
||||
import org.jetbrains.kotlin.gradle.plugin.diagnostics.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinGradleProjectChecker
|
||||
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinGradleProjectCheckerContext
|
||||
import org.jetbrains.kotlin.gradle.utils.toMap
|
||||
|
||||
/**
|
||||
* Report scenario when there are two targets of the same platform without distinguishing attribute
|
||||
*/
|
||||
internal object TargetsWithAmbiguousConsumableConfigurationsChecker : KotlinGradleProjectChecker {
|
||||
override suspend fun KotlinGradleProjectCheckerContext.runChecks(collector: KotlinToolingDiagnosticsCollector) {
|
||||
// Need all configurations to be created/set up
|
||||
KotlinPluginLifecycle.Stage.ReadyForExecution.await()
|
||||
|
||||
val allTargets = multiplatformExtension?.targets ?: return
|
||||
|
||||
val nonDistinguishableTargets = allTargets
|
||||
.mapNotNull { target ->
|
||||
val configuration = project.configurations.findByName(target.apiElementsConfigurationName) ?: return@mapNotNull null
|
||||
target.name to configuration
|
||||
}
|
||||
.groupBy { (_, consumableConfiguration) -> consumableConfiguration.attributes.toMap() }
|
||||
.values
|
||||
.filter { targetGroup -> targetGroup.size > 1 }
|
||||
.map { targetGroup -> targetGroup.map { (targetName, _) -> targetName } }
|
||||
|
||||
if (nonDistinguishableTargets.isEmpty()) return
|
||||
|
||||
val nonUniqueTargetsString = nonDistinguishableTargets.joinToString(separator = "\n") { targets ->
|
||||
val targetsListString = targets.joinToString { targetName -> "'$targetName'" }
|
||||
" * $targetsListString"
|
||||
}
|
||||
|
||||
collector.reportOncePerGradleProject(project, KotlinToolingDiagnostics.TargetsNeedDisambiguation(nonUniqueTargetsString))
|
||||
}
|
||||
}
|
||||
+3
-31
@@ -5,9 +5,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.unitTests.diagnosticsTests
|
||||
|
||||
import org.gradle.api.attributes.Attribute
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmWithJavaTargetPreset
|
||||
import org.jetbrains.kotlin.gradle.util.*
|
||||
import org.jetbrains.kotlin.gradle.util.androidLibrary
|
||||
import org.jetbrains.kotlin.gradle.util.checkDiagnosticsWithMppProject
|
||||
import org.jetbrains.kotlin.gradle.util.kotlin
|
||||
import org.junit.Test
|
||||
|
||||
class MppDiagnosticsFunctionalTest {
|
||||
@@ -99,35 +100,6 @@ class MppDiagnosticsFunctionalTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun targetsDisambiguation() {
|
||||
checkDiagnosticsWithMppProject("targetsDisambiguation") {
|
||||
kotlin {
|
||||
val distinguishAttribute = Attribute.of(String::class.java)
|
||||
|
||||
// Simple case: no disambiguation -> warning reported
|
||||
linuxArm64("linuxArm_A") { }
|
||||
linuxArm64("linuxArm_B") { }
|
||||
|
||||
// Some targets are disambiguated and some are not -> warning reported, only on targets without attribute
|
||||
jvm("jvm_A") { attributes { attribute(distinguishAttribute, "jvm1") } }
|
||||
jvm("jvm_B") { attributes { attribute(distinguishAttribute, "jvm2") } }
|
||||
jvm("jvm_C")
|
||||
jvm("jvm_D")
|
||||
|
||||
// Targets formally have attribute, but values are the same -> warning reported
|
||||
js("js_A") {
|
||||
browser()
|
||||
attributes { attribute(distinguishAttribute, "js") }
|
||||
}
|
||||
js("js_B") {
|
||||
browser()
|
||||
attributes { attribute(distinguishAttribute, "js") }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNoTargetsDeclared() {
|
||||
checkDiagnosticsWithMppProject("noTargetsDeclared") {
|
||||
|
||||
-96
@@ -1,96 +0,0 @@
|
||||
[KotlinTargetAlreadyDeclared | WARNING] Kotlin Target 'linuxArm64()' is already declared.
|
||||
Declaring multiple Kotlin Targets of the same type is deprecated.
|
||||
|
||||
i.e.
|
||||
kotlin {
|
||||
linuxArm64()
|
||||
linuxArm64("linuxArm_B") /* <- second 'linuxArm64' target in the project is deprecated */
|
||||
}
|
||||
|
||||
Please use different Gradle Projects or create Kotlin Compilations.
|
||||
For example:
|
||||
|
||||
kotlin {
|
||||
linuxArm64() {
|
||||
val linuxArm_B by compilations.creating
|
||||
}
|
||||
}
|
||||
----
|
||||
[KotlinTargetAlreadyDeclared | WARNING] Kotlin Target 'jvm()' is already declared.
|
||||
Declaring multiple Kotlin Targets of the same type is deprecated.
|
||||
|
||||
i.e.
|
||||
kotlin {
|
||||
jvm()
|
||||
jvm("jvm_B") /* <- second 'jvm' target in the project is deprecated */
|
||||
}
|
||||
|
||||
Please use different Gradle Projects or create Kotlin Compilations.
|
||||
For example:
|
||||
|
||||
kotlin {
|
||||
jvm() {
|
||||
val jvm_B by compilations.creating
|
||||
}
|
||||
}
|
||||
----
|
||||
[KotlinTargetAlreadyDeclared | WARNING] Kotlin Target 'jvm()' is already declared.
|
||||
Declaring multiple Kotlin Targets of the same type is deprecated.
|
||||
|
||||
i.e.
|
||||
kotlin {
|
||||
jvm()
|
||||
jvm("jvm_C") /* <- second 'jvm' target in the project is deprecated */
|
||||
}
|
||||
|
||||
Please use different Gradle Projects or create Kotlin Compilations.
|
||||
For example:
|
||||
|
||||
kotlin {
|
||||
jvm() {
|
||||
val jvm_C by compilations.creating
|
||||
}
|
||||
}
|
||||
----
|
||||
[KotlinTargetAlreadyDeclared | WARNING] Kotlin Target 'jvm()' is already declared.
|
||||
Declaring multiple Kotlin Targets of the same type is deprecated.
|
||||
|
||||
i.e.
|
||||
kotlin {
|
||||
jvm()
|
||||
jvm("jvm_D") /* <- second 'jvm' target in the project is deprecated */
|
||||
}
|
||||
|
||||
Please use different Gradle Projects or create Kotlin Compilations.
|
||||
For example:
|
||||
|
||||
kotlin {
|
||||
jvm() {
|
||||
val jvm_D by compilations.creating
|
||||
}
|
||||
}
|
||||
----
|
||||
[KotlinTargetAlreadyDeclared | WARNING] Kotlin Target 'js()' is already declared.
|
||||
Declaring multiple Kotlin Targets of the same type is deprecated.
|
||||
|
||||
i.e.
|
||||
kotlin {
|
||||
js()
|
||||
js("js_B") /* <- second 'js' target in the project is deprecated */
|
||||
}
|
||||
|
||||
Please use different Gradle Projects or create Kotlin Compilations.
|
||||
For example:
|
||||
|
||||
kotlin {
|
||||
js() {
|
||||
val js_B by compilations.creating
|
||||
}
|
||||
}
|
||||
----
|
||||
[TargetsNeedDisambiguation | WARNING] The following targets are not distinguishable:
|
||||
* 'js_A', 'js_B'
|
||||
* 'jvm_C', 'jvm_D'
|
||||
* 'linuxArm_A', 'linuxArm_B'
|
||||
Use an additional attribute to disambiguate them
|
||||
See https://kotlinlang.org/docs/multiplatform-set-up-targets.html#distinguish-several-targets-for-one-platform for more details
|
||||
Reference in New Issue
Block a user