fix(script): use compile instead analyze for scripts with deps (#1912)

This commit is contained in:
Skylot
2023-06-15 21:08:51 +01:00
parent 1a642108ef
commit 6f4451364b
11 changed files with 167 additions and 61 deletions
@@ -10,6 +10,7 @@ import kotlin.script.experimental.api.ScriptConfigurationRefinementContext
import kotlin.script.experimental.api.acceptedLocations
import kotlin.script.experimental.api.asSuccess
import kotlin.script.experimental.api.collectedAnnotations
import kotlin.script.experimental.api.compilerOptions
import kotlin.script.experimental.api.defaultImports
import kotlin.script.experimental.api.dependencies
import kotlin.script.experimental.api.ide
@@ -28,6 +29,7 @@ import kotlin.script.experimental.jvm.dependenciesFromCurrentContext
import kotlin.script.experimental.jvm.jvm
@KotlinScript(
displayName = "Jadx Script",
fileExtension = "jadx.kts",
compilationConfiguration = JadxScriptConfiguration::class,
)
@@ -66,7 +68,11 @@ object JadxScriptConfiguration : ScriptCompilationConfiguration({
onAnnotations(DependsOn::class, Repository::class, handler = ::configureMavenDepsOnAnnotations)
}
isStandalone(false)
isStandalone(true)
// forcing compiler to not use modules while building script classpath
// because shadow jar remove all modules-info.class (https://github.com/johnrengelman/shadow/issues/710)
compilerOptions.append("-Xjdk-release=1.8")
})
private val resolver = CompoundDependenciesResolver(FileSystemDependenciesResolver(), MavenDependenciesResolver())
@@ -75,10 +81,11 @@ fun configureMavenDepsOnAnnotations(context: ScriptConfigurationRefinementContex
val annotations = context.collectedData?.get(ScriptCollectedData.collectedAnnotations)
?.takeIf { it.isNotEmpty() }
?: return context.compilationConfiguration.asSuccess()
return runBlocking { resolver.resolveFromScriptSourceAnnotations(annotations) }
.onSuccess {
context.compilationConfiguration.with {
dependencies.append(JvmDependency(it))
}.asSuccess()
}
return runBlocking {
resolver.resolveFromScriptSourceAnnotations(annotations)
}.onSuccess {
context.compilationConfiguration.with {
dependencies.append(JvmDependency(it))
}.asSuccess()
}
}