Kotlin Script Support for JBang #1149
Unanswered
linux-china
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
kt is Kotlin source code, and kts is Kotlin Script Code, and they are different.
IntelliJ IDEA bundles Kotlin by default, and you can write any kts code in any project opened with IntelliJ IDEA even without kotlin in classpath. Of course, code completion is available for kts file.
kotlin-main-kts script ends with
.main.kts
and contains maven artifacts resolver, and not hard to parse and convert to JBang model.//DEPS
//REPOS
//SOURCES
demo.main.kts example:
IntelliJ IDEA can resolve artifacts for main.kts, and I think it's called script context. Code completion with third artifacts is available for script, and this is the main reason some developers choose to write main.kts and not Java.
Compare to kt file, main.kts has some advantages:
Groovy script shares same script context strategy alike kotlin script, and code completion is available from @grab annotation.
I will do some research about script context for normal Java file with plugin support, if it's available, and I think code with Java snippet is very convenient with code completion.
Compile kts or eval by kotlin command line?
Now you can use
kotlin demo.main.kts
to execute the kts file, but it's very slow and performance is not good. Compile main.kts withkotlinc demo.main.kts
may be good solution with JBang, and you can also compile main.kts to native byjbang --native demo.main.kts
.References:
Beta Was this translation helpful? Give feedback.
All reactions