What's the recommended way to write and run Kotlin...
# scripting
d
What's the recommended way to write and run Kotlin scripts with IntelliJ without building a full-blown project? It has "LightEdit" mode when opening a single script, but I can't even execute it without opening the file in a separate project. I'd like to be able to just write my script and execute it, like how easy it is to just write and execute a Python script with IDLE. The closest I've found is notebooks, but then I'm no longer actually creating a script file.
➕ 1
p
It you create a
kts
file with a
main
function or a
main.kts
file, there should be a "▶️" button before the first line of the file to run it
d
I'm not seeing that option.
a
even when you rename the file to
main.kts
?
d
Yes, same lack of Run button, and all options in the Run toolbar are disabled.
a
try renaming it to something like "demo.main.kts" the trailing ".main.kts" is crucial!
d
Even as
demo.main.kts
, I can't run it in Light Edit mode.
m
Kotlin Scripting is probably just not compatible with light edit mode. Very little is, it's not been a priority of JetBrains to make it work.
Scripting in general has been low priority. Sort of chicken/egg scenario.
v
@Derek Peirce hi, you can open kotlin script as file in intellij idea as is: no build system would be involved and highlighting, completion and running script should work. (I used upcoming idea 26.2 for recording)
but I've spotted some bugs on the way: for example, you have to choose jdk manually after the editor loaded also this
Script: .
bothers me a little bit. but I really would like to know your use-case so we can justify keeping this behaviour
tell me if this helps
m
Well, the use case is as said - scripts are often worked on in lightweight text editors because they're single file, usually, so IDE features like project management, build tools, cross-file navigation etc aren't worth the cost.
v
seems like it's covered already in 26.2
m
It's definitely much improved, thank you!
🤝 1
d
I've opened
demo.main.kts
in IntelliJ 2026.2, and still can't run the script. From your screenshot, you appear to be opening the script as its own project, rather than in LightEdit mode. How did you do that?
v
I opened a new project and just select a script
d
I'm trying to execute a script without the overhead of a project.