I'm trying to convert some of our bash/python scri...
# scripting
b
I'm trying to convert some of our bash/python scripts to .kts, and so far, the journey has been less than fluent so far. So far, I encountered a few issues, which makes it hard to sell it to the rest of the team at this moment. For example, the issue with Kotlin 1.3.50 to execute scripts isn't helping, so currently I run the scripts using
kotlinc -jvm-target 1.8 -cp /usr/local/Cellar/kotlin/1.3.50/libexec/lib/kotlin-main-kts.jar -script find-s3-by-tag.main.kts
, but there's more issues, such as: -
@file:DependsOn
blocks the whole IDE while it's retrieving dependencies, - running the scripts from IntelliJ results in weird errors:
Copy code
error: calls to static methods in Java interfaces are prohibited in JVM target 1.6. Recompile with '-jvm-target 1.8' (find-rds-by-tag.main.kts:46:28)
find-rds-by-tag.main.kts:25:31: error: calls to static methods in Java interfaces are prohibited in JVM target 1.6. Recompile with '-jvm-target 1.8'
    val stsClient = StsClient.builder()
(though I'm running on 1.8, and all settings are also on 1.8, yet still I can't execute the scripts). For most of them there are existing issues, or I've created issues but the above experience gives me the impression that Kotlin scripting is still in it's early stages. I'm just wondering what the current state is and I'm hoping that 1.3.60 will solve many of these issues.
3
i
Thank you very much for the feedback and for the issues. The scripting usability in the IDE is probably the least polished part of the functionality, unfortunately. We’re working on the improvements, and 1.3.60 will bring some, but definitely will not fix all the issues. Scripting support doesn’t have highest priority for us at the moment, therefore we’re spending relative limited amount of resources on improving it. One of the reasons for that is that the feedback so far is rather limited, so we do not see very high demand for it from the community. So, if you have any feedback or an opinion about the scripting, please do not hesitate to bring it forward.
b
Thanks Ilya for the reply. It's not only from the IDE, it's also from the CLI, but I think these issues are marked to be solved in 1.3.60. The feedback on scripting might be limited since it's in the current state it is? It took me quite a long time to figure out I had to call my scripts scriptname.main.kts. I'm not even sure if I really have to call them like this or not, but there if I omit the 'main' part, the script doesn't run. I'm hoping it's a bug or something.
Also, Googling for 'kotlin scripting' lands you on the command line compiler page. It's quite hard to find some good documentation on the scripting support.
but at the bottom of the page here: https://kotlinlang.org/docs/tutorials/command-line.html , there is one paragraph on running Kotlin scripts. If that's all the documentation you're providing, then well, it's quite poor.
besides that, if you execute the example, then you'll end up with the following error:
Copy code
~ epragt$ vim list_folders.kts
~ epragt$ kotlinc -script list_folders.kts /tmp
error: unable to instantiate class List_folders (list_folders.kts): java.lang.NoClassDefFoundError: kotlin/script/templates/standard/ScriptTemplateWithArgs
so, if that's the first user experience, I can imagine most people wouldn't be too enthusiastic to spend much time on it, me included. At this moment, I'll just mark Kotlin Scripting as 'alpha state', and at the moment, no serious candidate for replacing our Python scripts.
1
p
You may want to check out #kash_shell
b
@pabl0rg that's a shell, afaik?
p
Yes it’s a shell, which i take as another way to do scripting in kotlin
b
Sure. Not really what I'm looking for, but thanks for sharing.