Fix: Kotlin/Native libs have non-user friendly representation in IDE
Issue #KT-30288 Issue #KT-34998 Issue #KT-34400 (partially fixes)
This commit is contained in:
+24
-19
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.idea.configuration.DependencySubstitute.NoSubstitute
|
|||||||
import org.jetbrains.kotlin.idea.configuration.DependencySubstitute.YesSubstitute
|
import org.jetbrains.kotlin.idea.configuration.DependencySubstitute.YesSubstitute
|
||||||
import org.jetbrains.kotlin.idea.configuration.KotlinNativeLibraryNameUtil.buildIDELibraryName
|
import org.jetbrains.kotlin.idea.configuration.KotlinNativeLibraryNameUtil.buildIDELibraryName
|
||||||
import org.jetbrains.kotlin.idea.inspections.gradle.findKotlinPluginVersion
|
import org.jetbrains.kotlin.idea.inspections.gradle.findKotlinPluginVersion
|
||||||
import org.jetbrains.kotlin.idea.versions.bundledRuntimeVersion
|
|
||||||
import org.jetbrains.kotlin.konan.library.KONAN_STDLIB_NAME
|
import org.jetbrains.kotlin.konan.library.KONAN_STDLIB_NAME
|
||||||
import org.jetbrains.kotlin.konan.library.lite.LiteKonanLibraryFacade
|
import org.jetbrains.kotlin.konan.library.lite.LiteKonanLibraryFacade
|
||||||
import org.jetbrains.plugins.gradle.ExternalDependencyId
|
import org.jetbrains.plugins.gradle.ExternalDependencyId
|
||||||
@@ -117,27 +116,33 @@ internal class KotlinNativeLibrariesDependencySubstitutor(
|
|||||||
)
|
)
|
||||||
|
|
||||||
private val kotlinVersion: String? by lazy {
|
private val kotlinVersion: String? by lazy {
|
||||||
|
// first, try to figure out Kotlin plugin version by classpath (the default approach)
|
||||||
val classpathData = buildClasspathData(gradleModule, resolverCtx)
|
val classpathData = buildClasspathData(gradleModule, resolverCtx)
|
||||||
val result = findKotlinPluginVersion(classpathData)
|
val versionFromClasspath = findKotlinPluginVersion(classpathData)
|
||||||
if (result == null) {
|
|
||||||
val message = """
|
|
||||||
Unexpectedly can't obtain Kotlin Gradle plugin version for ${gradleModule.name} module.
|
|
||||||
Build classpath is ${classpathData.classpathEntries.flatMap { it.classesFile }}.
|
|
||||||
${KotlinNativeLibrariesDependencySubstitutor::class.java.simpleName} will run in idle mode. No dependencies will be substituted.
|
|
||||||
|
|
||||||
Hint: Please make sure that you have explicitly specified version of Kotlin Gradle plugin in `plugins { }` section.
|
if (versionFromClasspath == null) {
|
||||||
Example:
|
// then, examine Kotlin MPP Gradle model
|
||||||
|
val versionFromModel = mppModel.targets
|
||||||
|
.asSequence()
|
||||||
|
.flatMap { it.compilations.asSequence() }
|
||||||
|
.mapNotNull { it.kotlinTaskProperties.pluginVersion?.takeIf(String::isNotBlank) }
|
||||||
|
.firstOrNull()
|
||||||
|
|
||||||
plugins {
|
if (versionFromModel == null) {
|
||||||
kotlin("multiplatform") version "${bundledRuntimeVersion()}"
|
LOG.warn(
|
||||||
}
|
"""
|
||||||
""".trimIndent()
|
Can't obtain Kotlin Gradle plugin version for ${gradleModule.name} module.
|
||||||
if (ApplicationManager.getApplication().isUnitTestMode)
|
Build classpath is ${classpathData.classpathEntries.flatMap { it.classesFile }}.
|
||||||
LOG.warn(message)
|
${KotlinMPPGradleModel::class.java.simpleName} is $mppModel.
|
||||||
else
|
${KotlinNativeLibrariesDependencySubstitutor::class.java.simpleName} will run in idle mode. No dependencies will be substituted.
|
||||||
LOG.error(message)
|
""".trimIndent()
|
||||||
}
|
)
|
||||||
result
|
|
||||||
|
null
|
||||||
|
} else
|
||||||
|
versionFromModel
|
||||||
|
} else
|
||||||
|
versionFromClasspath
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getFileCollectionDependencySubstitute(dependency: FileCollectionDependency): DependencySubstitute =
|
private fun getFileCollectionDependencySubstitute(dependency: FileCollectionDependency): DependencySubstitute =
|
||||||
|
|||||||
Reference in New Issue
Block a user