Is it currently possible to run a script with mave...
# scripting
a
Is it currently possible to run a script with maven dependency in non-central repository?
i
If you mean - using resolver implementations from
kotlin-main-kts
or
kotlin-script-util
then - yes:
Copy code
@file:Repository("<https://jcenter.bintray.com>")
(see e.g. an example in the 1.3 RC blog post - https://blog.jetbrains.com/kotlin/2018/09/kotlin-1-3-rc-is-here-migrate-your-coroutines/)
a
Thanks! The documentation is still heavily fragmented
@ilya.chernikov The example does not seem to be working:
Copy code
html.kts:1:7: error: unresolved reference: Repository
@file:Repository("<https://jcenter.bintray.com>")
i
It works for me. What version are you using?
a
1.3.21 on windows 10. I am just running
kotlinc -cp  "C:\Users\darksnake\scoop\apps\kotlin\1.3.21\lib\kotlin-main-kts.jar" -script html.kts
Copy code
> kotlinc -version
info: kotlinc-jvm 1.3.21 (JRE 1.8.0_131-b11)
i
you have to give the script an extension “.main.kts”
a
let me try it
i
Sorry, it is not immediately clear, but the script customizations are defined in the script definition, and different scripts are recognized by an extension. The
kotlin-main-kts
defines scripts with support of resolving which are tied to the “.main.kts” extension.
a
Yep, now it works
Not obvious, but I can work with that. Do you plan to use some different way of applying customization. The extension-based way just does not feel right. Maybe some kind of universal annotation?
i
So far content-based approaches lead to heavy performance penalties, especially in IDE. So for a moment there are no plants to change it. But if we’ll find a technical possibility, we may reconsider it.
If you’re making your own customizer, you’re free to provide it for the default extension too. But it may lead to some clashes if used in some mixed environments.
a
I had the same problem with reading data files with meta and I end up using reserved first line declaration like sha-bang. So when I scan the file, I check if it has the first line like
#~<something here>~#
. And then read the whole file using this something. In case of scripts it seems like just using explicit command line argument and inferring from extension if it is not provided seems to be good backward-compatible way.
i
Shebang syntax is partially supported, in a sense that kotlin do not consider them errors. But using it as a file type detection in IDEA is quite difficult for deep technical reasons. But we’re keeping this in mind, so maybe we’ll find a way in the future.