Hi, I'm not active here but I want to ask somethin...
# scripting
s
Hi, I'm not active here but I want to ask something that I not test, kscript on IDEA using @file:MavenRepository + @file:DependsOnMaven, the IDEA can resolve that? If yes, three is any configuration to script definition that you can provide implicit repositories and dependencies just for the IDEA can give the dependencies resolution on the script?
i
Sorry, I think I do not understand your question. The
DependsOnMaven
and
MavenRepository
annotations are used mainly in the
kotlin jupyter kernel
. In the primary Kotlin repo, the annotations
DependsOn
and
Repository
are used instead. The "standard" definition that implements them is
kotlin-main-kts
- this module is distributed with the Kotlin command-line compiler as well as with the IntelliJ plugin, and can also be downloaded from maven central. If it doesn't answer your question, please tell.
s
Hi @ilya.chernikov, my bad about the wrong annotations, I was talking about this ones that you say. Sorry if I was not clear before, what I want to know if currently there is any configuration that I can ship with my script definition jar/dependency that IntelliJ could resolve it, like implicit imports and implicit repositories and maven dependencies.
i
The question is still not 100% clear, probably because the lack of documentation and an established terminology. The configuration that provides the functionality you descripbe is the essense of the script definition, so if you want to make your own definition with the functionality you need, you have to make it, that is - to create a configuration objects and the annotated definition base class. And for IntelliJ support in most case it would be enoght to put discovery file into your jar. But you probably want to reuse some functionality available in the other definitions, like one that processes maven dependencies. There is no plug-n-play solutions for that yet. But the easiest way for now, as far as I can tell, is to copy the approach that is used in the
kotlin-main-kts
. There is a distilled version of it - https://github.com/Kotlin/kotlin-script-examples/blob/master/jvm/simple-main-kts/SimpleMainKts.md (this is not-yet-official Kotlin scripting examples repo). There are some other - to my mind - harder - solutions too, so if this one dosen't suit you (or I misuderstood your aim again), please tell.
s
Hi @ilya.chernikov, tkx for sending this project, I clone it and test it out, Is awesome that
*.main.kts
the IntelliJ supports it automatically, but, in the case of custom script definition, such as
smain.kts
in the example, how can I make IntelliJ supports it (highlighted, navigation and implicit imports (the annotations is implicit imported if an understanding correctly) ) ? I need to add a dependency in the Gradle project that was
META-INF/kotlin/script/templates
and the IntelliJ already support that? You guys are thinking in add a configuration to Kotlin IntelliJ plugin to provide a list of script definition jars that we can use to make IntelliJ support automatically the script, such as with a URL to a jar file or a maven dependency with the
META-INF/kotlin/script/templates
? In scratch kts files for example we can choose the module classpath, could be nice you choose the script definition that we want to use.
i
The IntelliJ support is a difficult topic due to many constraints. There is a setting in
Preferences
->
Build, Execution, Deployment
->
Compiler
->
Kotlin Compiler
->
Kotlin Scripting
, that allow you to add specific script support without writing an IntelliJ plugin. There is also
Preferences
->
Languages & Frameworks
->
Kotlin
->
Kotlin Scripting
, where you can see which script support is currently loaded. But scratch files are not yet connected to the custom script processing, hopefully we'll support this someday too.
💯 1