My kotlin scripts are all really flaky because the...
# scripting
p
My kotlin scripts are all really flaky because they require a specific file in the same folder as the script. So when I don't execute them from the directory where they are located, they fail. Is there some way I can get the location of the script from inside the script?
m
Kscript has
System.getenv("KSCRIPT_FILE")
but I'm not sure it's available without kscript
Maybe that should be an issue ?
a
I had a proposal some time ago to include information in annotation instead of file name: https://youtrack.jetbrains.com/issue/KT-31021.
i
There is no standard way to do it, but you can implement it if you're using a custom script definition. For that you'll need to define a provided property in the compilation configuration, and then use evaluation configuration callback, defined via
refineBeforeEvaluation
to set it up to the script location, taking it from the cmpiled script.
1