what’s your most frequent use case for Kotlin scri...
# scripting
p
what’s your most frequent use case for Kotlin scripting? (this poll is a follow-up after a discussion in this thread) • 1️⃣ built-in .main.kts scripts - simply stand-alone
.main.kts
files • 2️⃣ custom standalone scripts -
.kts
files where you need to specify
fun main(…)
yourself • 3️⃣ custom embedded script host • 4️⃣ (option added later) scratch files in IDEA • 5️⃣ (option added later) through Gradle (mostly
build.gradle.kts
) • 6️⃣ (option added later) through kscript, to get more features • 7️⃣ other - please click 7️⃣ and specify in the comment, I’ll replace this option with your answer
4️⃣ 6
6️⃣ 4
1️⃣ 23
5️⃣ 35
3️⃣ 16
c
Scratch files in IDEA
👍 2
m
build.gradle.kts
is also a usage, although a very specific one
p
true! added an option, I guess it will be a popular one 🙂
🙏 1
c
Does
build.gradle.kts
count as Kotlin scripting? It came a lot earlier, I don't know if they reimplemented the plugin to use the Scripting machinery later
p
I’m not sure what is the origin of .gradle.kts, but from what I know, nowadays it’s implemented as a script host i.e. it’s a special case of Kotlin script
i.e. whatever improvements are made to scripting in general, they are likely to be propagated to Gradle Kotlin DSL
m
In 2019, it was made with scripting:

https://www.youtube.com/watch?v=OEFwnWxoazI

👍 2
Or at least they mention scripting quite often but not 100% sure how this translate in terms of actual low level APIs
m
I voted for (1) and (3) because we use it for the same sort of use case as .main.kts (general scripting) but it wasn't enough for us, so we built our own scripting host as a replacement.
👍 2
p
@mikehearn OOC, could you share what kind of extra things you decided to add in your scripting host?
m
k
I use https://github.com/kscripting/kscript Because the native .kts support doesn't have enough features (e.g. standalone cmd, unit test support, etc)
👍 1
p
@kenkyee unit test support made me wondering: how do you achieve it? I don’t see an example in the README edit: found: https://github.com/kscripting/kscript/blob/master/docs/user_guide.md#testing
k
You set it up as an intellij project.
👍 1
c
kscript was nice when it worked, but it's now almost two years that it's broken on Arch. I stopped using it long ago
k
What does "on Arch" mean? Forgot to mention I like being able to do "kscript <yourmainfile> --idea" to launch your intellij project...
m
What does "on Arch" mean?
I'm guessing Arch Linux
1
👍 1
I've stopped using kscript too. Found out that most of the time when I need to have unit tests, etc... I need a proper project anyways
The packaging options are nice but now that GitHub has native
*.main.kts
support it covers 90% of my needed 😄
🙂 1
p
GitHub has native
*.main.kts
support
what do you mean?
m
GitHub Actions has the kotlin CLI installed so you can frop a file with
Copy code
#!/usr/bin/env kotlin

println("Hello World")
And it'll all work in CI
👍🏾 1
today i learned 2
👍 3
d
I once had a strong use case for Kotlin scripting in an embedded host, on Android... Unfortunately I could never get it to work, the published engine refused to run on Android due to something arbitrary with bytecode level? Hope this could be lifted some day.
👀 1
m
Wait what? The Kotlin compiler doesn't run on Android?
I know this is quite the niche edge case but I'd be pretty curious how come this is not possible 😄
d
We wanted to implement a business rules engine on field devices for Australia's largest haulier.
Where the rules were scripts. Was hoping to migrate them from Rhino JS to KTS
😮 1
e
Android doesn't ship the components necessary to host javac either, kotlinc not working is in good company
👀 1
p
I use it to run code snippets in production, idk if that falls under 3 or 7
p
@PixelHamster interesting, could you give more details?
p
Well I run a discord bot and since there is a lot that I do t control in each server its useful to be able to run code in production to figure out why something behaves the way it does, I used to do this with the kotlin scriptengine but that broke when I started using context receivers so I switched to kotlin scripts recently
p
Like a REPL debugger in prod?
p
yes a repl kinda
p
ok, so I think it’s 3️⃣