Run gradle import instead of usage of scripting API during configurations update
For Gradle 6.0 or higher ^KT-34481
This commit is contained in:
+1
-1
@@ -176,7 +176,7 @@ internal class DefaultScriptConfigurationManager(project: Project) :
|
||||
val shouldLoad = isFirstLoad || loadEvenWillNotBeApplied || autoReloadEnabled
|
||||
if (!shouldLoad) return
|
||||
|
||||
val postponeLoading = isPostponedLoad && !autoReloadEnabled
|
||||
val postponeLoading = isPostponedLoad && !autoReloadEnabled && !isFirstLoad
|
||||
|
||||
if (!ScriptDefinitionsManager.getInstance(project).isReady()) return
|
||||
val scriptDefinition = file.findScriptDefinition() ?: return
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@file:Suppress("UnstableApiUsage")
|
||||
|
||||
package org.jetbrains.kotlin.idea.scripting.gradle
|
||||
|
||||
import com.intellij.openapi.externalSystem.importing.ImportSpecBuilder
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemUtil
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.plugins.gradle.settings.GradleProjectSettings
|
||||
import org.jetbrains.plugins.gradle.util.GradleConstants
|
||||
|
||||
fun runPartialGradleImport(project: Project) {
|
||||
// TODO: partial import
|
||||
val gradleSettings = ExternalSystemApiUtil.getSettings(project, GradleConstants.SYSTEM_ID)
|
||||
val projectSettings = gradleSettings.getLinkedProjectsSettings()
|
||||
.filterIsInstance<GradleProjectSettings>()
|
||||
.firstOrNull() ?: return
|
||||
|
||||
ExternalSystemUtil.refreshProject(
|
||||
projectSettings.externalProjectPath,
|
||||
ImportSpecBuilder(project, GradleConstants.SYSTEM_ID)
|
||||
.build()
|
||||
)
|
||||
}
|
||||
+6
@@ -78,6 +78,12 @@ class GradleScriptConfigurationLoader(project: Project) : DefaultScriptConfigura
|
||||
}
|
||||
}
|
||||
|
||||
val gradleVersion = getGradleVersion(project)
|
||||
if (gradleVersion != null && kotlinDslScriptsModelImportSupported(gradleVersion)) {
|
||||
runPartialGradleImport(project)
|
||||
return true
|
||||
}
|
||||
|
||||
val result = getConfigurationThroughScriptingApi(ktFile, vFile, scriptDefinition)
|
||||
context.saveNewConfiguration(vFile, result)
|
||||
return true
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.psi.KtCallExpression
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtScriptInitializer
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getChildrenOfType
|
||||
import org.jetbrains.plugins.gradle.settings.GradleLocalSettings
|
||||
import org.jetbrains.plugins.gradle.settings.GradleProjectSettings
|
||||
import org.jetbrains.plugins.gradle.util.GradleConstants
|
||||
|
||||
@@ -89,4 +90,16 @@ fun kotlinDslScriptsModelImportSupported(currentGradleVersion: String): Boolean
|
||||
|
||||
fun useScriptConfigurationFromImportOnly(): Boolean {
|
||||
return Registry.`is`("kotlin.gradle.scripts.useIdeaProjectImport", false)
|
||||
}
|
||||
|
||||
fun getGradleVersion(project: Project): String? {
|
||||
val gradleSettings = ExternalSystemApiUtil.getSettings(project, GradleConstants.SYSTEM_ID)
|
||||
val projectSettings = gradleSettings.getLinkedProjectsSettings()
|
||||
.filterIsInstance<GradleProjectSettings>()
|
||||
.firstOrNull()
|
||||
|
||||
if (projectSettings != null) {
|
||||
return GradleLocalSettings.getInstance(project).getGradleVersion(projectSettings.externalProjectPath)
|
||||
}
|
||||
return null
|
||||
}
|
||||
Reference in New Issue
Block a user