How do you work with IntelliJ and `*.main.kts` scr...
# scripting
m
How do you work with IntelliJ and
*.main.kts
scripts? Is it possible to define a script project without adding a
build.gradle.kts
/`settings.gradle.kts` ? Trying to create a run configuration for my scripts (very cool BTW) but I'm hit with
Project JDK has not been configured
j
I am able to add a jdk to project structure
πŸ‘€ 1
m
So you're just opening the script with
idea1 myscript.main.kts
?
If I try to do this while any other project is opened, it's opening in the context of that other project
j
I opened the folder which contain the script
image.png
πŸ‘ 1
that is the configuration
m
I opened the folder which contain the script
Fair enough πŸ‘ . That only works from the GUI though, right, not from command line (
./idea myscript.main.kts
), right?
m
We wrote an IntelliJ plugin for our kotlin scripting app. It wasn't that hard.
Then you can open scripts anywhere.
j
ah, from cli I use kotlin command tbh
kotlin myscript.main.kts
m
@mikehearn any chance this is open source?
j
which is the advantage of using that vs install kotlin with brew?
m
I'm talking about IDE support only
I want to run and debug inside IntelliJ
j
ah, the configuration I shared doesnt work with debug? I am gonna try
m
It's not, but I can show you the plugin code because it's just one file and I'm the boss so can randomly open source things at will πŸ˜‰ https://gist.github.com/mikehearn/fdcb2c3ef30c6a2970d089fd8f860216
πŸ™ 1
j
I can debug too πŸ€”
πŸ‘ 2
m
@Javier yea my point was I cannot open files in IntelliJ from the command line (with
./idea
)
j
ah okay
m
Trying this would fall back to whichever project was already open
m
Be aware that Kotlin Scripting + IDE plugins is very beta. We had to delete the META-INF registration file and switch to using the plugin all the time, to avoid the IDE screwing up its disk caches in random ways. Even now it's not really stable. There's a lot of fixes needed in the IDE.
πŸ‘ 1
Also with the plugin approach in that gist, intellij won't notice if the JARs change. So if you change the scripting host you need to restart the IDE because KTS plugins aren't dynamically loadable, it seems.
It's a road less travelled. But it does work! Good luck with it and feel free to hit me up with questions. it's the plugin for this (sorta unlaunched) bash competitor: https://hshell.hydraulic.dev/8.1/
Those are the only two files you should need. The rest can be generated by creating a plugin project in intellij
πŸ’™ 1
i
cc: @Andrei Klunnyi
a
Thank you, Ilya. cc: @Anton Yalyshev [JB]