darkmoon_uk
06/29/2025, 1:17 AM.kts
scripts instead of `.sh`; keeping more complex scripts in a powerful, familiar language.
Unfortunately the usefulness of kts
is unduly limited by IntelliJ IDE's failure to resolve symbols across @file:Import
dependencies - this is an essential feature for composing scripts together e.g. importing some library functions from a common.kts
- meanwhile the scripts still run fine, it's just IDE support that's lacking.
This problem has only become more impactful with junie Junie; as the agent sees 'unresolved' false positives and erroneously act upon them, struggling for a fix that never comes.
kodee sad This limitation is very sad, given it's been hanging for over 2 years...
KTIJ-16352 Scripts / IDE: unresolved reference when trying to import file in main.kts scripts with @Import annotation
Any insights into this issue in or outside of JB? Is scripting just abandoned beyond what's needed for Gradle? Such a shame, it's a killer feature in my book.mbonnin
06/29/2025, 10:57 AMImport
support would be quite important to organize scripts a bit bettermbonnin
06/29/2025, 10:59 AMImport
IDE support) and a bit of education, main.kts
could become quite big.darkmoon_uk
06/29/2025, 10:22 PM.main.kts
use-case would continue to be supported (implying that should include support for things like `Import`s in said main
scripts?).
I'm in a bit of a dilemma with it now - I like your suggestion of a single Clikt based script, but at 1,700 lines on the first cut, that's getting a bit unwieldy for man or machine.
My use case is total of 5 operations that prepare AWS at an org level then orchestrate Terraform operations at an App level within the org. It's mostly invoking other tools but I wanted to add in some safety for scoping out what objects already exist in the environment - hence the increased level of logic and draw towards kts
. Maybe I'll just recognise it as a full blown JVM project(!?)
...or just reluctantly go back to .sh
scripts. Once again, sad that @file:Import
breakage in the IDE is my nail in the coffin for kts
usage. I don't have the time to dig into the IDE integration source - that'd be a whole new area for me.mbonnin
06/29/2025, 10:34 PMit seems to suggest that at least theThis is what I understand as well, despite the relatively not engaging post. I wrote a follow up there: https://mbonnin.net/2024-11-21_state-of-kotlin-scripting/use-case would continue to be supported.main.kts
1,700 lines on the first cut, that's getting a bit unwieldy for man or machine.At that stage, another solution is to start pulling Gradle and make it a "real" project with
run
JavaExec task. Sure, it's a bit more boilerplate but doesn't take that long to setup.
Don't get me wrong, I'd still love to get support for @file:Import
but until this is supported, I'd rather have extra build.gradle
files than going back to .sh
filesdarkmoon_uk
06/29/2025, 10:36 PMdarkmoon_uk
06/29/2025, 10:37 PMkts
would be anyway; just without its sugar.mbonnin
06/29/2025, 10:40 PMsrc/main/kotlin
and build.gradle.kts
ceremony 🤷darkmoon_uk
06/29/2025, 10:49 PM./infra.main.kts org bootstrap
etc.darkmoon_uk
06/29/2025, 10:50 PMkts
🙃 🐢mbonnin
06/29/2025, 10:54 PMThere's a qualitative difference between saying 'go and compile this project, now invoke a JAR file buried in some output folder',Yea... Would be really cool to have
kotlinc
become as ubiquitous as sh
darkmoon_uk
06/29/2025, 10:55 PMdarkmoon_uk
06/29/2025, 10:55 PMPiotr Krzemiński
07/01/2025, 1:38 PMPiotr Krzemiński
07/01/2025, 1:39 PMPiotr Krzemiński
07/01/2025, 1:40 PMmbonnin
07/01/2025, 1:42 PMmbonnin
07/01/2025, 1:42 PMDependsOn
in my scripts 😞mbonnin
07/01/2025, 1:42 PMPiotr Krzemiński
07/01/2025, 1:46 PM@file:Import
that is finally coming 🎉mbonnin
07/01/2025, 1:47 PM@file:Import
just yet 😿mbonnin
07/01/2025, 1:47 PM@file:Import
support in IJ EAPs already?Piotr Krzemiński
07/01/2025, 1:48 PMVladislav Koshkin
07/01/2025, 3:13 PMdarkmoon_uk
07/02/2025, 12:06 AM.main.kts
scripts to a JVM CLI project, after giving up on scripting entirely because of this Import
issue.
Now you're telling me it's fixed?
I'm happy, really 🎉 😑
(seriously though, thank you for your work @Vladislav Koshkin - this is great news for Kotlin kodee happy )Vladislav Koshkin
07/04/2025, 8:42 AMease thehmm could you elaborate?requirement into something more standard and shorter, it deserves a transition to its own single extension.main.kts
darkmoon_uk
07/05/2025, 1:35 AM./myscript.kts
from command like instead of requiring that it be named .main.kts
. It's a minor change but would make Kotlin Scripting feel less like it requires special treatment, and more like any other .sh
invocation.
It's also an easy requirement for newcomers to miss - my own first attempts to run a kts
were frustrated because I didn't realise the .main.kts
naming was mandatory for an entry point.Piotr Krzemiński
07/05/2025, 10:48 AM.kts
, then I imagine the following compiler's behavior: if there's a fun main(...)
, treat it as an entry point (like today's .kts
). If there's no fun main(...)
, behave like today's .main.kts
. It's also an elegant way to converge to the single extensiondarkmoon_uk
07/05/2025, 11:47 AM.main
part as desirable or necessary - not sure why it was ever mandated (though I assume there was a reasoned decision made about it at some point).Piotr Krzemiński
07/05/2025, 11:58 AM.gradle.kts
(or any other custom script definition - I think that's the name) so captures some context where the code is compiled. However, the solution has matured enough to consider dropping the main
partmbonnin
07/05/2025, 12:17 PMmbonnin
07/05/2025, 12:17 PMkotlin build.gradle.kts
surely it's a mistake, even if it ends with .kts
mbonnin
07/05/2025, 12:19 PM.main
would certainly be acceptable now. This is also what kscript
used to do (and is still doing actually ^^)