jw
08/21/2020, 3:15 PM-d out
has no effect, and obviously I cannot compile without -script
.jw
08/21/2020, 4:00 PMKOTLIN_MAIN_KTS_COMPILED_SCRIPTS_CACHE_DIR=/path/to/build my-script.main.kts || true
mv /path/to/build/*.jar script.jar
jw
08/21/2020, 4:02 PMjw
08/21/2020, 5:21 PM-include-runtime
doesn't work with -script
😬jw
08/21/2020, 5:25 PMkenkyee
08/21/2020, 11:28 PMkenkyee
08/21/2020, 11:29 PMjw
08/21/2020, 11:45 PMaltavir
08/22/2020, 10:17 AMilya.chernikov
08/23/2020, 1:29 PMkotlinc
treats scripts the same way as regular kotlin sources, if you will omit the -script
argument, so you can compile your script into a jar with any options you want. But then you need a way to instantiate the script, in particular pass the proper set of args to the constructor. The main
function will be generated automatically and will try to convert args
to the constructor arguments, but it is not always reliable. And also the manifest attribute for the main class
is not set properly in this case. But yon the other hand, you can make an additional .kt
file with the proper main
and compile it along with the script.
- you can use a custom scripting host instead of the kotlinc
, compile script with compiler class and then save it with e.g. saveToJar
helper. This will create a runnable jar. (Actually main-kts
cache contains jars generated with this helper, therefore the hack with extracting jar from it works). The manifest of this jar contain links to all dependencies in the class-path
, but to make it self-contained, you may need to create your own helper similar to saveToJar
.jw
08/23/2020, 2:26 PMargs wouldn't be resolved (sorry Slack trapped me in dumb monospace)