Hello everyone and <@U0CHHN4F4>!! I have a case wh...
# scripting
g
Hello everyone and @ilya.chernikov!! I have a case where i need to see working a
.main.kts
script with a compiled jar runtime locally inside IntelliJ and in CI. More in specific: • i have a project where i compile a module with this jar that is going into:
build/libs/myJar.jar
• then i have a
MyScript.main.kts
where i use the library:
Copy code
@file:DependsOn("./build/libs/test-jar-main-kts-0.1.jar")

import com.test.jar.TestJar

print(TestJar.iAmTestJar())
If i run the script from IntelliJ works but the script gives an error :
File build/libs/myJar.jar
not found and i cannot benefit the autocomplete. By using the
/absolute/path/to/myJar.jar
it works well in IntelliJ with autocomplete and locally in general, but the path will be different whiles running on CI or another machine. Is there a way to have this working well both locally and on CI/other machine just using relative paths? Alternatively, how i can contribute to fix that? attached a screenshot
i
I understand the problem, but do not see an easy solution. The fundamental issue is that there is no a directory that could be considered a common base between a script in open in IDE and being run anywhere else. So, to solve this generically we will need some sort of env vars and/or special dirs expansion the same way it is usually implemented e.g. in unix shells. Although you can add such a mechanism into your own script definition, we are not ready to provide some generic enough one for the standard scripts. (Or at least I cannot think of a good solution now that wouldn't require significant investigations and design.) So, I can think of the following workarounds: - Use your own base directory with an absolute path, and put it to the
@file:Repository
annotation for simplicity - Use maven(ivy) resolver, and put your jar to the maven/ivy local cache (e.g. for the .main.kts` scripts, which uses ivy, the
~/.ivy2/cache
directory is usually used as a cache.) - Implement your own customized script definition, e.g. taking https://github.com/Kotlin/kotlin-script-examples/tree/master/jvm/simple-main-kts as a base, and add there a logic for the base directory settings.