cedric
08/02/2019, 12:23 AMfun gitComplete(line: String, cursorIndex: Int): List<String> {
val words = line.split(" ")
if (words[0] == "git") return listOf("commit", "status")
else return emptyList()
}
val result = if (args.size == 2) gitComplete(args[0], args[1].toInt())
else emptyList()
result
The script above returns a valid result (a list of strings), but if I remove the intermediate result
variable:
fun gitComplete(line: String, cursorIndex: Int): List<String> {
val words = line.split(" ")
if (words[0] == "git") return listOf("commit", "status")
else return emptyList()
}
if (args.size == 2) gitComplete(args[0], args[1].toInt())
else emptyList()
then the result of the evaluation by the engine is null
.jdemeulenaere
08/02/2019, 2:06 PMcedric
08/02/2019, 5:55 PM// ~/t/a.kts
fun hello() = "hello"
hello()
and
$ kotlinc -script ~/t/a.kts
exception: java.lang.ArrayIndexOutOfBoundsException: Index 10912 out of bounds for length 10912
at org.jetbrains.org.objectweb.asm.ClassReader.readUnsignedShort(ClassReader.java:2464)
jdemeulenaere
08/06/2019, 9:50 AMjdemeulenaere
08/07/2019, 12:08 PMefemoney
08/08/2019, 10:12 AM@DependsOn
or is it still Ivy for now? Like can we add maven repositories with the repo annotation?DALDEI
08/09/2019, 7:07 AMjdemeulenaere
08/09/2019, 10:53 AMjdemeulenaere
08/09/2019, 11:57 AMaltavir
08/10/2019, 2:42 PMExpecting 'hostConfiguration' property in the script compilation configuration for the script KtFile: script.kts
I tried to somehow provide this hostConfiguration
, but I just do not understand how it works.
My configuration looks like this:
val workspaceScriptConfiguration = ScriptCompilationConfiguration {
baseClass(Any::class)
implicitReceivers(WorkspaceBuilder::class)
defaultImports("hep.dataforge.workspace.*")
jvm {
dependenciesFromCurrentContext(wholeClasspath = true)
}
}
val evaluationConfiguration = ScriptEvaluationConfiguration {
implicitReceivers(builder)
}
BasicJvmScriptingHost().eval(source, workspaceScriptConfiguration, evaluationConfiguration)
jdemeulenaere
08/16/2019, 8:15 AMfogone
08/17/2019, 4:48 PMimplicitReceivers()
and trying to import another script using @file:Import("..")
annotation. In evalWithConfigAndOtherScriptsResults()
-- it's part of kotlin.script.experimental.jvm.BasicJvmScriptEvaluator
there is next code:
val ctor = java.constructors.single() // <-- generated constructor which expects (imported script result, implicit receiver)
val instance = ctor.newInstance(*args.toArray()) // <--- args here reversed, so (implicit receiver, imported script result)
did somebody meet this problem?efemoney
08/20/2019, 9:46 AMkotlin-scripting-jvm-host
is missing a dependency on kotlin-scripting-compiler(-embeddable)
in the pom. Had to explicitly specify it.josephivie
08/22/2019, 5:33 AMkotlinc -cp kts.jar -script test.kts
, where test.kts
is my script file and kts.jar
is the kotlin-main-kts
JAR from Maven, but I get 'Unable to find script definitions' and a bunch of errors related to it not knowing what the dependency annotations are. I'm following the tutorial as exactly as I understand it - what's missing?josephivie
08/22/2019, 5:42 AM.kts
files will be with this script runner, why is it not default? The complexity of use is keeping scripting from becoming widely useful. I'd like the equivalent python script.py
, and I'd like it to be part of installing Kotlin. Until it's that simple, I can't rely on distributing .kts
files to others as a consistent, portable, easy way of giving other people scripts.
I know kscript
exists, but it only supports *nix.josephivie
08/23/2019, 1:05 AM@Repository
and such, possibly with Maven Central and JCenter just implied - future-compatible support with normal Kotlin scripts top priority
- Interactive mode - load the KT/KTS file and then get a REPL
- Line Argument - run the KT/KTS file, providing the expression you wish to be executed in that context.
- Open in IntelliJ - creates a project in a temp folder, including needed files using hard links. Full auto-complete. Does not use Gradle under the hood, but rather direct IML files.
- Fully platform independent, running in Java without any platform-specific features nor a separate installation of Kotlin (use embedded compiler instead)
- Perhaps platform-specific GUI integration - double click on script file to run, context-menu edit...
Is this something people would be interested in?
I think it wouldn't take me too long - I've experimented with similar things already. I already know how to create IntelliJ projects from XML, running Kotlin scripts, running the embedded Kotlin compiler, etc.
I'd primarily use it for build-scripts, personally. It would be nice to ditch Gradle and anything Gradle-like in favor of straight-up using libraries from Maven to compile your stuff. That would be some nice standard reuse there. I can imagine creating a build.kts
file and then opening it in interactive mode in the terminal of IntelliJ to run tasks like build()
, run()
, publish()
, etc. It would be so much faster to edit (Gradle's KTS editing isn't too speedy and resolving plugins can be tricky) and would make build files easier to follow, as they'd just be more normal Kotlin without extra bulky configuration systems and magic plugins. No build system, just... Kotlin. I'd have to make a couple of Maven libraries to make it more convenient to set up, but that's not too bad.josephivie
08/23/2019, 2:19 AMjosephivie
08/23/2019, 2:21 AMDALDEI
08/24/2019, 1:25 PMjosephivie
08/25/2019, 7:51 AM.kts
proper files working - for whatever reason, the embedded compiler wouldn't compile them but the standalone one would. Also couldn't figure out how to get them playing well with plain IntelliJ projects. I'd love to learn more about the topic if anyone has information I couldn't find.Egor
08/25/2019, 11:55 AMLeon K
08/26/2019, 2:01 PMILakeful
08/26/2019, 9:23 PMException in thread "..." java.lang.NoSuchMethodError: Line_1.access$getExample$p(LLine_1;)Ljava/lang/String;
darkmoon_uk
09/01/2019, 12:44 AMDALDEI
09/01/2019, 11:48 PMDALDEI
09/05/2019, 11:58 AMNikky
09/06/2019, 3:47 PMPaul Woitaschek
09/17/2019, 8:41 AMjdemeulenaere
09/22/2019, 12:07 PMbamboo
09/23/2019, 8:26 PMScriptDependenciesResolver
that reads the data from the given script resolver environment which can be configured via the -Xscript-resolver-environment
command line argument. The custom resolver is setup via the ScriptTemplateDefinition
annotation:
https://github.com/gradle/gradle/blob/6f683805c6b782b1eb91c01591aecabe6fe535fb/subprojects/kotlin-dsl/src/main/kotlin/org/gradle/kotlin/dsl/precompile/PrecompiledProjectScript.kt#L52-L54
My understanding is that it is NOT possible to mix the legacy ScriptTemplateDefinition
annotation with the new KotlinScript
one to get both, the dynamic implicit imports computed from the script resolver environment plus the implicit receivers from a custom compilationConfiguration
setup.
So the question is then, does the experimental API allow for the list of default imports for a given script to be computed based on command line arguments passed to the compiler?
@KotlinScript(
compilationConfiguration = DynamicDefaultImportsConfiguration::class
// other settings
)
open class ScriptWithDynamicDefaultImports
object DynamicDefaultImportsConfiguration : ScriptCompilationConfiguration({
refineConfiguration {
beforeCompiling {
it.compilationConfiguration.with {
defaultImports(
// How to read arguments passed to the compiler from here?
TODO()
)
}.asSuccess()
}
}
})
bamboo
09/23/2019, 8:26 PMScriptDependenciesResolver
that reads the data from the given script resolver environment which can be configured via the -Xscript-resolver-environment
command line argument. The custom resolver is setup via the ScriptTemplateDefinition
annotation:
https://github.com/gradle/gradle/blob/6f683805c6b782b1eb91c01591aecabe6fe535fb/subprojects/kotlin-dsl/src/main/kotlin/org/gradle/kotlin/dsl/precompile/PrecompiledProjectScript.kt#L52-L54
My understanding is that it is NOT possible to mix the legacy ScriptTemplateDefinition
annotation with the new KotlinScript
one to get both, the dynamic implicit imports computed from the script resolver environment plus the implicit receivers from a custom compilationConfiguration
setup.
So the question is then, does the experimental API allow for the list of default imports for a given script to be computed based on command line arguments passed to the compiler?
@KotlinScript(
compilationConfiguration = DynamicDefaultImportsConfiguration::class
// other settings
)
open class ScriptWithDynamicDefaultImports
object DynamicDefaultImportsConfiguration : ScriptCompilationConfiguration({
refineConfiguration {
beforeCompiling {
it.compilationConfiguration.with {
defaultImports(
// How to read arguments passed to the compiler from here?
TODO()
)
}.asSuccess()
}
}
})
nastelaz
09/24/2019, 9:16 AMilya.chernikov
09/24/2019, 11:54 AMget(ScriptCompilationConfiguration.hostConfiguration)?.get(ScriptingHostConfiguration.getEnvironment)?.invoke()
but more importantly, since you can use your own host, you can add a new key to the compilation configuration and pass required parameters via it directly, without using command line.
But maybe it’s a bit too early for gradle to switch to the new API anyway: I had an intention to implement a refinement callback for “sections”, to remove necessity to use the lexer directly on your side. But if you’re eager to use new API, I can probably try to prioritize this task as well.bamboo
09/24/2019, 11:58 AMsince you can use your own host, you can add a new key to the compilation configuration and pass required parameters via it directly, without using command line.
ilya.chernikov
09/24/2019, 12:08 PMbamboo
09/24/2019, 12:08 PMilya.chernikov
09/24/2019, 12:12 PMbamboo
09/24/2019, 12:14 PMcompileKotlin
tasks somehow?ilya.chernikov
09/24/2019, 12:16 PMbamboo
09/24/2019, 12:16 PMcompileKotlin
task which has its configuration augmented by the kotlin-dsl
pluginkotlin-dsl
plugin adds the required script templates to the classpath and configures the script environment via freeCompilerArgs
ilya.chernikov
09/24/2019, 12:22 PMbamboo
09/24/2019, 12:27 PMilya.chernikov
09/24/2019, 12:30 PMkotlin-dsl
extension to it.
So you can either continue to use “environment” hack, until we’ll come up with anything, or can create your own out-of-band data exchange.bamboo
09/24/2019, 12:37 PMScriptDependenciesResolver
to compute the classpathilya.chernikov
09/24/2019, 12:39 PMbamboo
09/24/2019, 12:40 PMilya.chernikov
09/24/2019, 12:42 PMKotlinScript
annotation, In this case the IDE support should work out of box.bamboo
09/24/2019, 12:42 PMIn this case the IDE support should work out of box.
ScriptDependenciesResolver
in that case would beilya.chernikov
09/24/2019, 12:44 PMbamboo
09/24/2019, 12:47 PM-script-templates
compiler argument to tell exactly which templates should be used.ilya.chernikov
09/24/2019, 12:49 PMIt’s just not clear to me at this point what the replacement for theIn your example above, the block:in that case would beScriptDependenciesResolver
refineConfiguration {
beforeCompiling {
is one of the “resolvers” in the old API - it is a callback that is called by the compiler, so you can change compilation configuration according to your needs. So, e.g. now in this block you can add dependencies to the configuration.bamboo
09/24/2019, 12:49 PMSo, e.g. now in this block you can add dependencies to the configuration.
ilya.chernikov
09/24/2019, 12:50 PMMaybe we should move the precompiled script templates to a separate module.The problem with distinction is IDE-specific, we can easily separate compilation, but in the IDE we have a single set of templates per project.
bamboo
09/24/2019, 12:50 PMThe problem with distinction is IDE-specific, we can easily separate compilation, but in the IDE we have a single set of templates per project.
ilya.chernikov
09/24/2019, 12:52 PMbamboo
09/24/2019, 12:52 PMilya.chernikov
09/24/2019, 1:03 PMbamboo
09/24/2019, 1:04 PMFor a moment we ignore (in the IDE) all dependencies that are coming from the configuration for scripts
ilya.chernikov
09/24/2019, 1:05 PMbamboo
09/24/2019, 1:06 PMilya.chernikov
09/24/2019, 1:08 PMbamboo
09/24/2019, 1:08 PMilya.chernikov
09/24/2019, 1:11 PMrefineConfiguration {
onSections("plugins", "dependencies") {
that would allow you to process sections of the scripts without using the lexer directly. What do you think about such an API?bamboo
09/24/2019, 1:18 PMplugins
/ buildscript
/ initscript
sections as separate scriptsilya.chernikov
09/24/2019, 1:20 PMonSections
block, you need to execute another compiler for the section before continuing with the results.bamboo
09/24/2019, 1:20 PMilya.chernikov
09/24/2019, 1:21 PMbamboo
09/24/2019, 1:23 PMplugins { java }
java { }
plugins
block before we can compile the rest of the scriptProgram
(that’s what we call this uniform façade to the scripts)plugins
section at this point because we know it needs to run every timeProgram
that executes the precompiled plugins
script and THEN compiles the rest after the plugins have been appliedilya.chernikov
09/24/2019, 1:42 PMonSections
callback doesn’t fit your use case. I’ll think about it further. I still don’t like the fact that you’re using compiler internals. Maybe the old (and still unused) solution with the source-sections
compiler plugin should be revived after all.bamboo
09/24/2019, 1:43 PM-script-templates
anymore now that I changed from ScriptTemplateDefintion
to KotlinScript
ilya.chernikov
09/24/2019, 1:47 PMbamboo
09/24/2019, 1:47 PMilya.chernikov
09/24/2019, 1:48 PM-Pplugin:kotlin.scripting:script-definitions=...
or - better - use script definitions discovery mechanism.bamboo
10/07/2019, 5:18 PMKotlinScript
annotation for compilation worked out great and Gradle 6.0 will ship with the new implicit receiver based script templates. Thanks again!ilya.chernikov
10/08/2019, 6:20 AMbamboo
10/08/2019, 2:37 PM@KotlinScript
based template yesterday but I didn’t manage to get it to see the baseClass(...)
I gave the template, will continue to investigate it later.@ScriptTemplateDefinition
to get the classpath and default imports but get the remaining settings (mainly implicitReceivers
) from the `@KotlinScript`’s compilationConfiguration
?ilya.chernikov
10/08/2019, 2:56 PMbamboo
10/08/2019, 3:10 PMannotationsForSamWithReceivers
has no effect in IntelliJ, should it be supported already?ilya.chernikov
10/09/2019, 10:19 AMannotationsForSamWithReceivers
- will check whether I can fix it quickly.
About the implicit receiver - I need to dig a bit deeper.bamboo
10/09/2019, 12:13 PMilya.chernikov
10/10/2019, 3:15 PMsamWithReceiver
is a bit worse then I thought. I need some more time to implement required functionality for the new scripting API. I’ll try to do it as soon as possible, but I’m by far not sure if it is not already too late for 1.3.60.
Anyway, here is the issue to watch - https://youtrack.jetbrains.com/issue/KT-34294bamboo
10/10/2019, 4:07 PMilya.chernikov
10/10/2019, 4:36 PMTmpod
01/25/2020, 11:26 PMilya.chernikov
01/27/2020, 10:41 AMTmpod
01/27/2020, 10:47 AMilya.chernikov
01/27/2020, 10:47 AMTmpod
01/27/2020, 10:49 AMilya.chernikov
01/27/2020, 10:59 AMTmpod
02/11/2020, 7:14 PM