Get rid of kotlinx-coroutines usage in scripting libs and plugins

the dependency on the coroutines library caused various problems like
KT-30778, or stdlib/runtime version conflicts.
The only function used was `runBlocking`, so this change replaces it
with the internal implementation based on the similar internal thing
from the stdlib.
#KT-30778 fixed
This commit is contained in:
Ilya Chernikov
2021-07-16 11:02:17 +02:00
committed by TeamCityServer
parent 9b1de90452
commit 0cd29adcc7
20 changed files with 89 additions and 67 deletions
@@ -17,7 +17,6 @@ dependencies {
compile(project(":kotlin-scripting-jvm"))
compile(kotlinStdlib())
compileOnly(project(":kotlin-reflect-api"))
compile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core"))
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
compileOnly(intellijDep()) { includeJars("asm-all", rootProject = rootProject) }
@@ -5,11 +5,11 @@
package org.jetbrains.kotlin.scripting.resolve
import kotlinx.coroutines.runBlocking
import kotlin.script.dependencies.Environment
import kotlin.script.dependencies.ScriptContents
import kotlin.script.experimental.dependencies.AsyncDependenciesResolver
import kotlin.script.experimental.dependencies.DependenciesResolver
import kotlin.script.experimental.impl.internalScriptingRunSuspend
// wraps AsyncDependenciesResolver to provide implementation for synchronous DependenciesResolver::resolve
class AsyncDependencyResolverWrapper(
@@ -18,8 +18,9 @@ class AsyncDependencyResolverWrapper(
override fun resolve(
scriptContents: ScriptContents, environment: Environment
): DependenciesResolver.ResolveResult
= runBlocking { delegate.resolveAsync(scriptContents, environment) }
): DependenciesResolver.ResolveResult =
@Suppress("DEPRECATION_ERROR")
internalScriptingRunSuspend { delegate.resolveAsync(scriptContents, environment) }
suspend override fun resolveAsync(
@@ -16,7 +16,6 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiManager
import com.intellij.testFramework.LightVirtualFile
import kotlinx.coroutines.runBlocking
import org.jetbrains.kotlin.idea.KotlinLanguage
import org.jetbrains.kotlin.psi.KtAnnotationEntry
import org.jetbrains.kotlin.psi.KtFile
@@ -34,6 +33,7 @@ import kotlin.script.experimental.dependencies.AsyncDependenciesResolver
import kotlin.script.experimental.dependencies.DependenciesResolver
import kotlin.script.experimental.dependencies.ScriptDependencies
import kotlin.script.experimental.host.*
import kotlin.script.experimental.impl.internalScriptingRunSuspend
import kotlin.script.experimental.jvm.*
import kotlin.script.experimental.jvm.compat.mapToDiagnostics
import kotlin.script.experimental.jvm.impl.toClassPathOrEmpty
@@ -255,7 +255,8 @@ fun refineScriptCompilationConfiguration(
// runBlocking is using there to avoid loading dependencies asynchronously
// because it leads to starting more than one gradle daemon in case of resolving dependencies in build.gradle.kts
// It is more efficient to use one hot daemon consistently than multiple daemon in parallel
runBlocking {
@Suppress("DEPRECATION_ERROR")
internalScriptingRunSuspend {
resolver.resolveAsync(scriptContents, environment)
}
} else {