Fix import when android gradle plugin is involved in IDEA 183
All dependencies on MPP modules are added in KotlinAndroidGradleMPPModuleDataService including transitive ones. Fixes KT-30510 in IDEA 183 and below
This commit is contained in:
+28
-8
@@ -22,6 +22,7 @@ import com.intellij.openapi.module.Module
|
|||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.roots.DependencyScope
|
import com.intellij.openapi.roots.DependencyScope
|
||||||
import com.intellij.openapi.roots.ModifiableRootModel
|
import com.intellij.openapi.roots.ModifiableRootModel
|
||||||
|
import com.intellij.openapi.util.registry.Registry
|
||||||
import com.intellij.openapi.vfs.VfsUtil
|
import com.intellij.openapi.vfs.VfsUtil
|
||||||
import com.intellij.util.SmartList
|
import com.intellij.util.SmartList
|
||||||
import com.intellij.util.containers.stream
|
import com.intellij.util.containers.stream
|
||||||
@@ -160,6 +161,10 @@ class KotlinAndroidGradleMPPModuleDataService : AbstractProjectDataService<Modul
|
|||||||
it.kotlinSourceSet?.actualPlatforms?.supports(platform) ?: false
|
it.kotlinSourceSet?.actualPlatforms?.supports(platform) ?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun List<DataNode<GradleSourceSetData>>.filterByPlatform(platform: KotlinPlatform) = this.filter {
|
||||||
|
it.kotlinSourceSet?.actualPlatforms?.supports(platform) ?: false
|
||||||
|
}
|
||||||
|
|
||||||
private fun addExtraDependeeModules(
|
private fun addExtraDependeeModules(
|
||||||
moduleNode: DataNode<ModuleData>,
|
moduleNode: DataNode<ModuleData>,
|
||||||
projectNode: DataNode<ProjectData>,
|
projectNode: DataNode<ProjectData>,
|
||||||
@@ -167,6 +172,7 @@ class KotlinAndroidGradleMPPModuleDataService : AbstractProjectDataService<Modul
|
|||||||
rootModel: ModifiableRootModel,
|
rootModel: ModifiableRootModel,
|
||||||
testScope: Boolean
|
testScope: Boolean
|
||||||
) {
|
) {
|
||||||
|
val legacyMode = !Registry.get("kotlin.android.import.mpp.all.transitive").asBoolean()
|
||||||
val dependeeModuleNodes = getDependeeModuleNodes(moduleNode, projectNode, modelsProvider, testScope)
|
val dependeeModuleNodes = getDependeeModuleNodes(moduleNode, projectNode, modelsProvider, testScope)
|
||||||
val relevantNodes = dependeeModuleNodes
|
val relevantNodes = dependeeModuleNodes
|
||||||
.flatMap { ExternalSystemApiUtil.getChildren(it, GradleSourceSetData.KEY) }
|
.flatMap { ExternalSystemApiUtil.getChildren(it, GradleSourceSetData.KEY) }
|
||||||
@@ -179,15 +185,29 @@ class KotlinAndroidGradleMPPModuleDataService : AbstractProjectDataService<Modul
|
|||||||
|
|
||||||
val gradleSourceSetDataNodes = SmartList<DataNode<GradleSourceSetData>>()
|
val gradleSourceSetDataNodes = SmartList<DataNode<GradleSourceSetData>>()
|
||||||
.apply {
|
.apply {
|
||||||
addIfNotNull(
|
if (legacyMode) {
|
||||||
(if (isAndroidModule) relevantNodes.firstByPlatformOrNull(KotlinPlatform.ANDROID) else null)
|
addIfNotNull(
|
||||||
?: relevantNodes.firstByPlatformOrNull(KotlinPlatform.JVM)
|
(if (isAndroidModule) relevantNodes.firstByPlatformOrNull(KotlinPlatform.ANDROID) else null)
|
||||||
)
|
?: relevantNodes.firstByPlatformOrNull(KotlinPlatform.JVM)
|
||||||
addIfNotNull(
|
)
|
||||||
relevantNodes.firstOrNull {
|
addIfNotNull(
|
||||||
(it.kotlinSourceSet?.actualPlatforms?.supports(KotlinPlatform.COMMON) ?: false) && it.kotlinSourceSet?.kotlinModule?.name == commonSourceSetName
|
relevantNodes.firstOrNull {
|
||||||
|
(it.kotlinSourceSet?.actualPlatforms?.supports(KotlinPlatform.COMMON) ?: false) && it.kotlinSourceSet?.kotlinModule?.name == commonSourceSetName
|
||||||
|
}
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
val androidSourceSets = if (isAndroidModule) relevantNodes.filterByPlatform(KotlinPlatform.ANDROID) else emptyList()
|
||||||
|
if (androidSourceSets.isEmpty()) {
|
||||||
|
addAll(relevantNodes.filterByPlatform(KotlinPlatform.JVM))
|
||||||
|
} else {
|
||||||
|
addAll(androidSourceSets)
|
||||||
}
|
}
|
||||||
)
|
addAll(
|
||||||
|
relevantNodes.filter {
|
||||||
|
(it.kotlinSourceSet?.actualPlatforms?.supports(KotlinPlatform.COMMON) ?: false) && it.kotlinSourceSet?.kotlinModule?.name == commonSourceSetName
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val testKotlinModules =
|
val testKotlinModules =
|
||||||
|
|||||||
@@ -100,5 +100,10 @@
|
|||||||
description="Enable manual editing of MPP target platforms"
|
description="Enable manual editing of MPP target platforms"
|
||||||
defaultValue="false"
|
defaultValue="false"
|
||||||
restartRequired="false"/>
|
restartRequired="false"/>
|
||||||
|
<registryKey key="kotlin.android.import.mpp.all.transitive"
|
||||||
|
description="Add all transitive dependencies on MPP modules when Android project is imported"
|
||||||
|
defaultValue="true"
|
||||||
|
restartRequired="false"/>
|
||||||
|
|
||||||
</extensions>
|
</extensions>
|
||||||
</idea-plugin>
|
</idea-plugin>
|
||||||
|
|||||||
@@ -104,5 +104,10 @@
|
|||||||
description="Use new Java to Kotlin Converter (experimental)"
|
description="Use new Java to Kotlin Converter (experimental)"
|
||||||
defaultValue="true"
|
defaultValue="true"
|
||||||
restartRequired="false"/>
|
restartRequired="false"/>
|
||||||
|
<registryKey key="kotlin.android.import.mpp.all.transitive"
|
||||||
|
description="Add all transitive dependencies on MPP modules when Android project is imported"
|
||||||
|
defaultValue="true"
|
||||||
|
restartRequired="false"/>
|
||||||
|
|
||||||
</extensions>
|
</extensions>
|
||||||
</idea-plugin>
|
</idea-plugin>
|
||||||
|
|||||||
@@ -96,5 +96,10 @@
|
|||||||
description="Use new Java to Kotlin Converter (experimental)"
|
description="Use new Java to Kotlin Converter (experimental)"
|
||||||
defaultValue="true"
|
defaultValue="true"
|
||||||
restartRequired="false"/>
|
restartRequired="false"/>
|
||||||
|
<registryKey key="kotlin.android.import.mpp.all.transitive"
|
||||||
|
description="Add all transitive dependencies on MPP modules when Android project is imported"
|
||||||
|
defaultValue="true"
|
||||||
|
restartRequired="false"/>
|
||||||
|
|
||||||
</extensions>
|
</extensions>
|
||||||
</idea-plugin>
|
</idea-plugin>
|
||||||
|
|||||||
@@ -95,5 +95,10 @@
|
|||||||
description="Use new Java to Kotlin Converter (experimental)"
|
description="Use new Java to Kotlin Converter (experimental)"
|
||||||
defaultValue="true"
|
defaultValue="true"
|
||||||
restartRequired="false"/>
|
restartRequired="false"/>
|
||||||
|
<registryKey key="kotlin.android.import.mpp.all.transitive"
|
||||||
|
description="Add all transitive dependencies on MPP modules when Android project is imported"
|
||||||
|
defaultValue="true"
|
||||||
|
restartRequired="false"/>
|
||||||
|
|
||||||
</extensions>
|
</extensions>
|
||||||
</idea-plugin>
|
</idea-plugin>
|
||||||
|
|||||||
Reference in New Issue
Block a user