diff --git a/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/experimental/plugins/KotlinNativeBasePlugin.kt b/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/experimental/plugins/KotlinNativeBasePlugin.kt index d12da298dcd..f0b9f708bab 100644 --- a/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/experimental/plugins/KotlinNativeBasePlugin.kt +++ b/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/experimental/plugins/KotlinNativeBasePlugin.kt @@ -185,6 +185,7 @@ class KotlinNativeBasePlugin: Plugin { private fun Project.addInteropTasks() { val settingsToTask = mutableMapOf() + val namesWithWarning = mutableSetOf() components.withType(AbstractKotlinNativeBinary::class.java) { binary -> binary.component.dependencies.cinterops.all { cinterop -> val konanTarget = binary.konanTarget @@ -206,6 +207,22 @@ class KotlinNativeBasePlugin: Plugin { binary.linkElements.get().outgoing.artifact(interopTask.outputFileProvider) { it.classifier = "interop-${cinterop.name}" } + // User can create an interop with the same name as the main library. + // In this case we get two libraries with the same name and one of them depends + // on the another. Such a situation is considered as a cyclic dependency by the compiler + // so we warn a user about it. + val mainLibraryName = binary.linkFile.get().asFile.nameWithoutExtension + val interopLibraryName = interopTask.outputFile.nameWithoutExtension + + if (mainLibraryName == interopLibraryName && mainLibraryName !in namesWithWarning) { + logger.warn(""" + + Warning: you have an interop with the same name as the main library ($mainLibraryName)! + It may cause failures in dependent projects so consider renaming the interop. + + """.trimIndent()) + namesWithWarning.add(mainLibraryName) + } } } }