Do not configure module SDK after the Gradle import if it was set explicitly with the Gradle Idea plugin (fixes KT-27530)

If `kotlinOptions.jdkHome` is set, this will still override the setting from the Gradle Idea plugin.
This commit is contained in:
Ingo Kegel
2018-10-11 13:45:28 +02:00
committed by asedunov
parent 06e0fde74f
commit d853fcb642
2 changed files with 10 additions and 1 deletions
@@ -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) {
@@ -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<Boolean>("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<String>
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<String>,
defaultArguments: List<String>,