What do you mean exactly? I have this file at the ...
# scripting
l
What do you mean exactly? I have this file at the root of an Android Studio project (which uses Kotlin and
.gradle.kts
), but the syntax highlighting is not there apart from keywords and strings as I said.
g
What exactly doesn't work? You don't have access to your plugins directly applied in root script?, it's long story, plugins block isn't supported yet for script plugins (see Kotlin DSL issue tracker to get more context), better to use buildSrc instead as suggested by Nikky
l
I am not writing
gradle.kts
files but just
.kts
file. What is not working is syntax highlighting besides reserved keywords. To get it, I have to prefix
.kts
with
.gradle
, which is a workaround. I think I'll stick to this while they improve scripting support in next Kotlin versions.
g
In a pure kts file you should have stdlib, but maybe something broken
l
I have, but the IDE just doesn't offer syntax highlighting, and links to compiled stdlib instead of stdlib with sources… unless I do the mentioned workaround
a
To get a
.kts
script with highlighting, navigation, etc. you should add a compile "org.jetbrains.kotlinkotlin script runtime1.3.10" dependency to your build script and place the script file under a source root, ex.
src/main/java/script.kts
. Out-of-module scripts are not currently supported. See also https://youtrack.jetbrains.com/issue/KT-27853#focus=streamItem-27-3159647-0-0
g
@Alexey Belkov [JB] Hmmm, why kotlin-script-runtime is not applied by default? At lest would be good to allow use stdlib for generic kts files this is reasonable default that at least allow to have simple kotlin scripts support. Because KT-27853 related to usage of kotlin-main-kts, which, as I understand, not the same as kotlin-script-runtime
1
i
The behavior depends on where your script is located. If it is placed under a source root of some project, along with other sources, the project’s classpath us used for the script (script runtime could be missing by default, but there is a quickfix about it.) If it is placed outside of the source roots, as in case of “build.gradle.kts” files, the highlighting is rudimentary by default (for all files, not only for kts), so you need to add special support to the IDE to make it full-blown.
g
Yes, I understand this, that a script related to some particular project can project dependencies, have own script definition etc But I'm talking about support of standard library.
kotlinc -script some.kts
doesn't require explicitly specify stdlib jar and just works, I believe this should be also default behavior of Kotlin Idea plugin, just because it's default behavior of kotlinc and it's not practical to use Kotlin without stdlib. Probably Idea just should implicitly use bundled stdlib for any kts without script definition or opened outside of any project
1