diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleSourceSetDataService.kt b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleSourceSetDataService.kt index 620893a48f0..e58a16e95c5 100644 --- a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleSourceSetDataService.kt +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleSourceSetDataService.kt @@ -282,6 +282,7 @@ fun configureFacetByGradleModule( ideModule.compilerArgumentsBySourceSet = moduleNode.compilerArgumentsBySourceSet ideModule.sourceSetName = sourceSetName } + ideModule.hasExternalSdkConfiguration = sourceSetNode?.data?.sdkName != null val argsInfo = moduleNode.compilerArgumentsBySourceSet?.get(sourceSetName ?: "main") if (argsInfo != null) { diff --git a/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt b/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt index 34496441789..a92aaed96ff 100644 --- a/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt @@ -25,6 +25,7 @@ import com.intellij.openapi.roots.ExternalProjectSystemRegistry import com.intellij.openapi.roots.ModuleRootManager import com.intellij.openapi.roots.ModuleRootModel import com.intellij.openapi.roots.ProjectRootManager +import com.intellij.openapi.util.Key import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.text.StringUtil import org.jetbrains.kotlin.cli.common.arguments.* @@ -41,8 +42,12 @@ import org.jetbrains.kotlin.idea.util.application.runWriteAction import org.jetbrains.kotlin.platform.IdePlatform import org.jetbrains.kotlin.platform.IdePlatformKind import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind +import org.jetbrains.kotlin.psi.NotNullableUserDataProperty import kotlin.reflect.KProperty1 +var Module.hasExternalSdkConfiguration: Boolean + by NotNullableUserDataProperty(Key.create("HAS_EXTERNAL_SDK_CONFIGURATION"), false) + private fun getDefaultTargetPlatform(module: Module, rootModel: ModuleRootModel?): IdePlatform<*, *> { val platformKind = IdePlatformKind.ALL_KINDS.firstOrNull { getRuntimeLibraryVersions(module, rootModel, it).isNotEmpty() @@ -231,7 +236,7 @@ private val CommonCompilerArguments.ignoredFields: List private fun Module.configureSdkIfPossible(compilerArguments: CommonCompilerArguments, modelsProvider: IdeModifiableModelsProvider) { // SDK for Android module is already configured by Android plugin at this point - if (isAndroidModule(modelsProvider)) return + if (isAndroidModule(modelsProvider) || hasNonOverriddenExternalSdkConfiguration(compilerArguments)) return val projectSdk = ProjectRootManager.getInstance(project).projectSdk val allSdks = ProjectJdkTable.getInstance().allJdks @@ -261,6 +266,9 @@ private fun Module.configureSdkIfPossible(compilerArguments: CommonCompilerArgum } } +private fun Module.hasNonOverriddenExternalSdkConfiguration(compilerArguments: CommonCompilerArguments): Boolean = + hasExternalSdkConfiguration && (compilerArguments !is K2JVMCompilerArguments || compilerArguments.jdkHome == null) + fun parseCompilerArgumentsToFacet( arguments: List, defaultArguments: List,