Hello, today I wanted to write a script in Kotlin,...
# scripting
n
Hello, today I wanted to write a script in Kotlin, but I'm completely lost. Maybe you could give me some guidance. • I'm an Android dev using Android Studio • I want to write a script to move / rename files in a folder. Nothing fancy but I would like to avoid using bash and use Kotlin instead. • The resulting "script" should be usable easily by the other team members or the CI machine, in Windows or Mac. • The resulting "script" should be readable and modifiable by other devs (and not the compiled .jar) So I tried: • https://umang91.medium.com/scripting-in-kotlin-eaf01750bbee which was soooo promising but I see the
kotlin
CLI is already dead ? Such a same it seemed such a beautiful and powerful replacement for bash files 😞 • Then I tried Kotlin Notebook but they never mentionned that it needed Intellij Ultimate. I lost half a day trying to download the plugin until I understood. Greedy fuckers 😞 • Then I tried
ki shell
but I don't quite understand what is it for. Looks like Kotlin Playground locally, which doesn't fit my need. • Then I'm trying to use
kotlinc -script
but there's no documentation (https://kotlinlang.org/docs/command-line.html#run-scripts), or I don't understand the relation between the overly complex documentation linked there (https://kotlinlang.org/docs/custom-script-deps-tutorial.html) and a simple CLI-invoked script in Kotlin. Please guide me in this maze I'm already on the verge to going back to bash scripting. What tool would you use to produce the specified script ?
p
hi! AFAIK, the topic of portability between OSes is tricky, i.e. for Windows we need special treatment. But in general, for unix-based OSes, the shebang approach works fine. Just create a file like
my-script.main.kts
, make it executable, and put there e.g.:
Copy code
#!/usr/bin/env kotlin

println("Hello from Kotlin scripting!")
why would you say
kotlin
CLi is dead?
n
Thanks for the quick response ! Following https://umang91.medium.com/scripting-in-kotlin-eaf01750bbee, the first step is already not working, after installing the compiler (https://kotlinlang.org/docs/command-line.html#install-the-compiler), I can't use
kotlin my-file.main.kts
like in the article. It says "kotlin is not found" in my console. I'm sorry even if it's not my first rodeo, I'm so lost there's nothing "official" to read about and every bit of documentation about kotlin scripting is so confusing, everything is deprecated / not working anymore.
v
And yeah, "Greedy fuckers", really. Why do they not do all work for free. They do not deserve to get any payback for the excellent work they do!
1
💯 1
p
oh, I didn't catch it, I was so eager to help
n
They deserve it for making me lose half a day because they didn't mention in the documentation that it only works with Ultimate, yes. That's deceptive at best, greedy at worst.
p
https://plugins.jetbrains.com/plugin/16340-kotlin-notebook "Compatible with IntelliJ IDEA Ultimate"
Not a single ultimate mention in the docs
v
It's right on the plugin page as Piotr has shown. Don't blame them for you not reading compatibility notes.
n
https://blog.jetbrains.com/kotlin/2024/11/state-of-kotlin-scripting-2024/ Not a single ultimate mention in the last blog post
It's every worst in the blog post tbh, I quote :
Meanwhile, we are improving the Kotlin Notebook plugin for IntelliJ IDEA
That's truely deceptive lol
https://plugins.jetbrains.com/plugin/16340-kotlin-notebook
Who still uses a website to download plugins ? I was trying to download it from the "plugins manager" in Android Studio as everyone does
v
I never do that, I don't even use Android Studio
p
in the IDE it's pretty clear it works only with Ultimate, I don't see how you wasted half a day
👆 1
n
image.png
It's not.
p
wrong plugin
n
I know
It's just not there, so it's quite hard to understand the "ultimate only" part, right ?
v
If it's not there it is obviously not compatible with your version
And if in doubt, you can always go to the plugin page where it is clearly shown
p
it is true, though, that JB could standardize on their "only in premium" note, like they use a note e.g. here: https://www.jetbrains.com/help/pycharm/configuring-remote-interpreters-via-ssh.html
still, the wording used in the original post is too strong
n
If it's not there it is obviously not compatible with your version
Yeah I figured it out after half a day, even if I worked for 10 years on Android Studio
v
And it is their fault that you need half a day to open a website? o_O
n
to this day I didn't even knew what "ultimate" meant. I'm using Android Studio. To be it's irrelevant which intellij I'm using. And, stupid from me, I expected Android Studio to be based on Ultimate since, you know, Android is a big part in Kotlin ecosystem and growth
And it is their fault that you need half a day to open a website? o_O
I didn't even know there would be a WEBSITE for plugins lol We have a working plugin manager in the software Is the year 2004 ?
v
Judging by your behaviour, yes.
n
Anyway, I'll go back to shell scripting. Less drama and it works on any computer
v
The sources you quoted the plugin is for IntelliJ IDEA, not for Android Studio. So even if a plugin is compatible with IntelliJ IDEA Community Edition does not mean it is compatible with Android Studio. You just assumed that.
And actually, it would be ridiculous if AS would be based on IJ Ultimate. Why should anyone by IJ Ultimate if they could just use AS to get everything for free? o_O
Besides all your inappropriate statements here, Kotlin Scripting works perfectly fine and will continue to work fine. In the blog post you linked to they also stated it will stay and be maintained.
n
You just assumed that.
Like the other android dev I asked around me lol Every single other plugin I used / downloaded / heard of was working with Android Studio. So, if I read "this plugin is working with Intellij Idea", and I can't make it work, the fault is cleary in the missleading docs / blogpost. IF there would be a mention of "Intellij Idea ULTIMATE / PAY ONLY / PREMIUM" or whatever, yeah, that would be my bad. But defending "hey try this super awesome plugin on Intellij Idea" is deafening. The documentation should be 100% clear and not commercially / politically influenced. That's what I like about Kotlin instead of Java. Clear, simple, on the point. The scripting part is CLEARLY not. I guess that's why it's failing so hard, and that's a bummer because I liked the
./kotlin script.kts
idea a lot.
v
Like the other android dev I asked around me lol
They assume it is based on IntelliJ IDEA? That is fine and correct, but still does not mean that plugins working for one work for the other. If they assume that a free product is based on a paid product in that scale, that would be a bit naive. 🤷‍♂️
The scripting part is CLEARLY not.
... from your point of view For me the scripting is quite clear and working just fine, I used it often already. If you would learn how to properly behave in an open community of users and just asked for help instead of starting your post with swearing inappropriately, you would probably already have a working setup.
n
Usually when the docs are honest and / or clear, I don't even have to handle the drama in the community. Also, the community is way nicer and understanding in other channels. I don't even understand how you can still defend such a deceptive wording. It has no place in a development space. Beside the Ultimate fiasco part, that's a bit frustrating to spend half a day trying to write a 20 line script in Kotlin without any clear documentation / tutorial / conflicting articles. To my understanding, even if I managed to make
kotlin
or
kotlinc
work, my script would not be working anymore in Kotlin 2.4 (source `CLI REPL (via
kotlinc
) will continue to function at least until the release of Kotlin 2.3, but its operation will be limited to compatibility mode, i.e. with the
-language-version 1.9
option set (and may require an opt-in flag starting from release 2.2).` https://blog.jetbrains.com/kotlin/2024/11/state-of-kotlin-scripting-2024/)
v
REPL != Running Scripts
They said
.main.kts
scripts will stay and be further maintained and improved
And I don't need to defend deceptive wording, because I do not see any deceptive wording
This community is very nice and understanding. But it - or at least me - is not understanding when people are violating the code of conduct and also common sense how you communicate in an open community.
We are even very understanding, trying to show you your wrong behavior instead of just getting a moderator to handle it
n
I can't call people greedy when their actions clearly are motivated by software selling instead of documentation in a clearly developer-targeted blogpost and even on the documentation itself ??? How is it violating any kind of code of conduct ? They violated the "implicit" kind of conduct where documentation is 100% true and full and I'm talking on it, yes. I paid for Jetbrain products before (Code With Me was great when it worked) so it's not a "paying" issue. Since they are removing scripting CLI capabitilies and "hidding scripting support" behind a paywall, yup, that's greedy. Deal with it. Greedy and stupid when you think about it since we can't even pay for "Android Studio Ultimate" if we wanted to.
v
I can't call people greedy
Calling them "greedy" would still be non-sense, but acceptable. Calling them "greedy fuckers" is not acceptable. JetBrains provides many things for free like IntelliJ IDEA Community Edition and thus Android Studio, Kotlin, .... A greedy company would not do that.
when their actions clearly are motivated by software selling
They are a software company, what do you expect? That they provide every product for free?
instead of documentation in a clearly developer-targeted blogpost and even on the documentation itself ???
For me it is clearly documented. Documentation could be improved as always. But there is nothing misleading in what they wrote, it just might not be clear enough for every reader and no documentation will ever be.
How is it violating any kind of code of conduct ?
You do not see how calling them "greedy fuckers" might be against the CoC? Really? o_O
They violated the "implicit" kind of conduct where documentation is 100% true and full
Documentation is never 100% true. The moment you write documentation it is almost already outdated and not 100% true. There is no such "kind of conduct".
Since they are removing scripting CLI capabitilies
They do not, as said multiple times, scripting on the CLI is there and will stay, they even committed to it in the blog post you mentioned as said before. Again, REPL has nothing to do with scripting. REPL is an interactive shell where you enter something and get the result, much like the Kotlin Notebooks. Scripting is you write a script to a file and then can execute that file and that continues to work and will also be maintained further as already mentioned multiple times. As you more want scripting than a REPL from what you said, the plugin you are upset about is anyway not what you are after as it is more REPL / playground like, not scripting.
and "hidding scripting support" behind a paywall,
I don't see how scripting is in any way behind any paywall. A plugin to add interactive Kotlin-playing as functionality into the IDE requires a paid version of that IDE. But that has nothing to do with Scripting at all.
👍 4