mbonnin
06/21/2026, 5:16 PMmain.kts files now that kotlin is kotlin toolchain? I get this
$ kotlin foo.main.kts
Usage: kotlin [<options>] <command> [<args>]...
Error: no such subcommand foo.main.ktsJoffrey
06/21/2026, 6:19 PMkotlin executable named kotlinr (TBD) and we'll also add support to run scripts in the Kotlin ToolchainVampire
06/21/2026, 7:58 PMkotlinc -script foo.main.kts insteadmbonnin
06/21/2026, 10:58 PMkotlinc is not part of the kotlin toolchain, right? I have to install it separately?Vampire
06/22/2026, 6:18 AMkotlinc and maybe even the old kotlin are around.mbonnin
06/22/2026, 6:26 AMJoffrey
06/22/2026, 7:44 AMJoffrey
06/22/2026, 7:45 AMkotlinc for scripts is not ideal. Hence we why we're trying to address this.mbonnin
06/22/2026, 8:24 AMkotlinr ?Vampire
06/22/2026, 9:19 AMkotlin is mainly a wrapper around kotlinc with supplying proper arguments afair.Vampire
06/22/2026, 9:20 AM*.main.kts file.
For this the kotlin call should not require further arguments to run the script, because a Shebang with (multiple) arguments is not portable.Joffrey
06/23/2026, 1:25 PMkotlin run script.main.kts it would indeed have the portability problem you mention.mbonnin
06/23/2026, 1:29 PMVampire
06/23/2026, 1:38 PMkotlin run script.main.kts would work.
One argument between the executable and the file should be portable.
As long as the shebang does not use env like #!/usr/bin/env kotlin which is a security issue anyway.
In that case the run would be a second parameter which is then not portable.
With #!/what/ever/kotlin run it should be portable, but only works if you know the path to the kotlin executable.mbonnin
06/24/2026, 10:13 PMkotlinr it is, right?
https://github.com/JetBrains/kotlin/pull/6289Joffrey
07/13/2026, 8:41 AMkotlinr executable will be present in the Kotlin compiler distribution 2.4.10. It's better to replace your shebangs to this if you want to use both scripting and the Kotlin Toolchain together for now.Joffrey
07/13/2026, 8:45 AMkotlin run --script foo.main.kts (which can be simplified to kotlin run foo.main.kts if you run it outside any project) in the most recent dev versions of the Kotlin Toolchain, but I'm not sure this will be a long term solution. We're contemplating the idea of focusing on running single .kt files (real Kotlin files with a main function) instead of scripts, which are a bit of an oddity in the Kotlin language.Joffrey
07/13/2026, 8:46 AMkotlin do X cover what you need? Do you use scripts for some other types of tasks, outside Kotlin projects?
2. Do you usually have a single file? Or does it import others? (Do you ever use @file:Import?)
3. Do you often need Maven dependencies? If yes, are they always the same (e.g. coroutines/serialization/ktor client)? Or do you often use random dependencies, like a specific SDK or something?mbonnin
07/13/2026, 8:50 AMmbonnin
07/13/2026, 8:51 AMmbonnin
07/13/2026, 8:53 AMJoffrey
07/13/2026, 8:53 AMbecause I don't want to pay configuration timeWould reading the project model (< 0.5s) count as configuration time in your mind? Or are you referring specifically to Gradle's configuration phase?
mbonnin
07/13/2026, 8:54 AMmbonnin
07/13/2026, 8:55 AMmbonnin
07/13/2026, 8:55 AMJoffrey
07/13/2026, 8:56 AMbut my email filters scripts don't need a build toolBut those wouldn't live inside a project anyway, right?
mbonnin
07/13/2026, 8:56 AMmbonnin
07/13/2026, 8:56 AMmbonnin
07/13/2026, 8:56 AMJoffrey
07/13/2026, 8:57 AMkotlin do X with the plugin approach (hopefully streamlined a bit better) only for project-management things that already live in a project. The case for "a single file that lives on its own" is still relevant, and this is the case for which I was asking 2) and 3).mbonnin
07/13/2026, 8:58 AMfile:Import. As soon as I need 2 files, I create a proper projectmbonnin
07/13/2026, 8:58 AMmbonnin
07/13/2026, 8:59 AM@file:DependsOn all the time (JSON parsers, io, CSV, etc...)Joffrey
07/13/2026, 9:00 AMmodule.yaml file, and to move your file under src, and you are good to go. So I'm assuming it might be ok to require a "real project" (a module.yaml) when you have 2+ files. The remaining question being dependencies.mbonnin
07/13/2026, 9:01 AMJavaExec task for one-of things (in Gradle land) and TBH, that works quite well. I don't need specific plugin support I think? "Just" an easy way to start a process locally with a given classpathVampire
07/13/2026, 9:03 AMcould you please share your use cases for scripting? Things like:While it is also nice to have Kotlin for writing - well - scripts instead of using Bash or similar, what I mainly use it for is github.com/typesafegithub/github-workflows-kt to write typesafe convenient GitHub Actions Workflow files in Kotlin instead of bloody YAML files. Especially for more complex ones like github.com/Vampire/setup-wsl/blob/…/test.main.kts. cc @Piotr Krzemiński
Do you usually have a single file? Or does it import others? (Do you ever useYes, definitely, to be able to follow DRY.?)@file:Import
Do you often need Maven dependencies?Yes, always
If yes, are they always the same (e.g. coroutines/serialization/ktor client)?No, always different.
Joffrey
07/13/2026, 9:03 AMI don't need specific plugin support I think? "Just" an easy way to start a process locally with a given classpathYeah the ergonomics question of how to declare a custom command will most likely come later. If this became the recommended way to do management tasks, we will probably want to work on reducing boilerplate for them.
mbonnin
07/13/2026, 9:05 AMJavaExec task. The task takes classpath and java version as input.Joffrey
07/13/2026, 9:05 AMsrc/
main.kt
other.kt
module.yaml # 'product: jvm/app' + dependencies, maybe more if you need
And run with kotlin runVampire
07/13/2026, 9:08 AMJoffrey
07/13/2026, 9:08 AMgithub-workflow-kt author could provide some executable to serve as runtime to simplify the generation), which is able to load and run scripts with its own rules, without the need for the Kotlin Toolchain to be able to run it in a simple command.Vampire
07/13/2026, 9:10 AMgithub-workflow-kt is not an action.
It is just a Kotlin library that allows to write GHA workflow files as Kotlin scripts conveniently.
You can currently simple execute that scirpt and get the necessary YAML file produced.Joffrey
07/13/2026, 9:10 AMVampire
07/13/2026, 9:11 AMJoffrey
07/13/2026, 9:11 AMkotlin run to do the generation. At that point you're not really leveraging the fact that those workflows are scriptsJoffrey
07/13/2026, 9:13 AMgithub-workflow-kt library, so you can use a nice DSL to express your workflow
• you run the script (in some way), which generates real Github workflow YAML files
• you commit these YAML files to make Github process themVampire
07/13/2026, 9:14 AMJoffrey
07/13/2026, 9:22 AMgithub-workflow-kt case seems to be about managing workflows that are for a project. If this project is already a Kotlin Toolchain project, then this workflow generation could just be a local plugin module exposing a generateWorkflows custom command. And then you could do kotlin do generateWorkflows. It's a very mild downgrade in convenience (you have to mode your script file to some dir, but you can run it really easily too. You can also manage the location of the generated YAML, and even make sure they are in sync as part of your build by registering a check for this. I guess you could even do this for Gradle projects in general, by writing a Gradle plugin.
If this is not a Kotlin Toolchain nor Gradle project (I guess not a Kotlin project at all), you could use the single-module project approach I mentioned above, and just run kotlin run instead of ./my-workflow.main.kts (or just click the play button in IJ, which is completely equivalent). The github-workflow-kt library author could add any scaffolding they need to make it easy to write a main() function (they're kinda already there).Joffrey
07/13/2026, 9:23 AMbeing able to run the script as is as executable file is quite handyDo you see drawbacks in the above approaches regarding this? Would some of these make it less handy (e.g.
kotlin do generateWorkflows or kotlin run?)Joffrey
07/13/2026, 9:23 AMAlso for Bash-script replacements.yeah I was mostly considering the Github workflows case right now
Vampire
07/13/2026, 9:30 AMTheYes, but they are independent of any project setup. They can be for a Kotlin project with Gradle build, but they can also be for literally anything you run a GHA for. And it must not be run through any build tool, because before even running the actual build, the consistency of the YAML with the Workflow script must be ensured as GitHub does not yet have a built-in support for this.case seems to be about managing workflows that are for a project.github-workflow-kt
Do you see drawbacks in the above approaches regarding this? Would some of these make it less handy (eYes, definitely. I have in
~/bin a file foo.main.kts and then I can run anywhere on my computer foo bla to run the script just like any other command or bash script on the path.
With those I would have to make it a polyglot script if possible so that it is a bash script that runs itself with running ktlin run or have second "starter script" that runs the actual script.
And also providing such scripts as commands through package managers will have the same drawbacks etc.
yeah I was mostly considering the Github workflows case right nowFor the GHA case it is still handy that you can as fast as possible run the command, especially as it runs before each workflow execution to ensure consistency of the YAML. I indeed usually also have a
proprocessWorkflows Gradle task if it is in a Gradle project to be able to run the scripts as Gradle task and as part of the check task.
But as I said, the GHA workflow YAML generation is absolutely independent of the type of project or build tool and should even run without any build tool being available.Piotr Krzemiński
07/13/2026, 9:37 AMJoffrey
07/13/2026, 7:40 PMAnd it must not be run through any build tool, because before even running the actual build, the consistency of the YAML with the Workflow script must be ensured as GitHub does not yet have a built-in support for thisHow does it work for you right now? You later said it actually went through the Gradle build tool, integrated with the
check task, so I'm not sure I followVampire
07/13/2026, 9:04 PMPiotr Krzemiński
07/14/2026, 3:46 AM