https://kotlinlang.org logo
Join Slack
Powered by
# scripting
  • r

    ritesh

    05/09/2025, 3:11 PM
    Wanted to get a sense of people if they are using k-script in CI and if there had been any gotchas or pain-points as compared to shell scripting or python-scripting, when to comes to debugging and other factors.
    v
    c
    • 3
    • 8
  • d

    Daniel Pitts

    05/10/2025, 4:41 PM
    Is it possible to use Kotlin Scripting as a way to allow extending a C++ program? For example, if I were to create a game engine in C++, and wanted to enable Kotlin scripting, would there be an easy way to do that?
    e
    m
    j
    • 4
    • 8
  • r

    Rob Elliot

    05/24/2025, 7:36 PM
    Apologies for the cross post, but perhaps people here have more experience of this?
    👀 1
    v
    l
    v
    • 4
    • 10
  • a

    AndrewStone

    06/27/2025, 8:56 PM
    Running a kotlin Jsr223 script engine, can the "host" programatically loop through all the global symbols inside the ScriptEngine?
  • d

    darkmoon_uk

    06/29/2025, 1:17 AM
    I really enjoy being able to write
    .kts
    scripts instead of `.sh`; keeping more complex scripts in a powerful, familiar language. Unfortunately the usefulness of
    kts
    is unduly limited by IntelliJ IDE's failure to resolve symbols across
    @file:Import
    dependencies - this is an essential feature for composing scripts together e.g. importing some library functions from a
    common.kts
    - meanwhile the scripts still run fine, it's just IDE support that's lacking. This problem has only become more impactful with junie Junie; as the agent sees 'unresolved' false positives and erroneously act upon them, struggling for a fix that never comes. kodee sad This limitation is very sad, given it's been hanging for over 2 years... KTIJ-16352 Scripts / IDE: unresolved reference when trying to import file in main.kts scripts with @Import annotation Any insights into this issue in or outside of JB? Is scripting just abandoned beyond what's needed for Gradle? Such a shame, it's a killer feature in my book.
    ⭐ 1
    plus one 1
    👍 8
    👍🏾 2
    m
    p
    v
    • 4
    • 32
  • s

    Stylianos Gakis

    07/04/2025, 2:35 PM
    Trying to give a shot to kotlin scripting for GH actions and I am stumped on this issue: I want to do something as simple as write something to GH env variables. Not using kotlin scripting I can do
    Copy code
    - name: This works
      run: echo SOME_VAR=asd >> $GITHUB_ENV
    - name: Using it
      run: echo $SOME_VAR
      env:
        SOME_VAR: ${{ env.SOME_VAR }}
    And this works perfectly fine. In Kotlin I try to do:
    Copy code
    runCommand("echo SOME_VAR=asd >> \$GITHUB_ENV")
    (where runCommand comes from here https://github.com/apollographql/apollo-kotlin/blob/65dd7a44a74ed016988777521248da164de32ea0/scripts/bump-kotlin-nightlies.main.kts#L71C1-L85C2 basically using
    ProcessBuilder
    ) And then I try to do the same exact
    Using it
    task, but nothing at all gets printed. The contents of
    SOME_VAR
    are just empty. Is this some issue with ProcessBuilder, or something I am doing which is wrong here?e
    m
    e
    p
    • 4
    • 12
  • m

    mbonnin

    07/27/2025, 2:58 PM
    Is there a way to debug what's happening when I click "synchronize" in a
    *.main.kts
    file? Like output or something? It won't import my dependencies but I'm unsure why...
    d
    • 2
    • 5
  • j

    joseph_ivie

    07/28/2025, 3:27 PM
    Someone mentioned this to me earlier: Is it possible to use KotlinX serialization in a
    *.main.kts
    ? It would be incredibly useful.
    e
    v
    • 3
    • 2
  • o

    Olaf Gottschalk

    08/01/2025, 5:10 AM
    When using the
    BasicScriptingHost.eval(...)
    function to run script code, is there any way, a script can programmatically add elements to the
    reports
    property of the
    ResultWithDiagnostics
    that it returns? In some situations that are caught at runtime of my script, I want to return a warning just like a compiler warning, but my script can only detect this at runtime like when a user does something they are not intended to do. My current "solution" is to log a warning using a logger... but this is really not what I want. I need this information as a side-information along with the result of the script evaluation. So, ideally, in my script, I would like to call a function that adds elements to this collection of
    ScriptDiagnostic
    elements with a severity of warning... Is that possible?
    i
    • 2
    • 2
  • t

    Tim Putnam

    08/05/2025, 8:30 PM
    I'm using kotlin 2.2.0, with
    BasicJvmScriptingHost
    embedded in an application that's dynamically loading JPMS modules using
    ModuleLayer
    . I simply want the classloader from this
    ModuleLayer
    to be visible to the compiler. I"m setting
    baseClassLoader
    in the host configuration thus:
    Copy code
    val hostconf = ScriptingHostConfiguration {
            jvm {
                baseClassLoader(appClassloader)
            }
        }
    I've also tried a variety of ways to set the classloader in the
    ScriptCompilationConfiguration
    but to no avail. I don't want to add explicit jars (e.g.
    dependenciesFromClassloader()
    ). I just want it to use a provided classloader, but it always just uses the main/boot classloader. This is something I've had working at some stage in the pass, but now doesn't seem to. I feel like I'm missing something obvious - it seems to want external files? Please, any pointers?
    m
    • 2
    • 2
  • d

    darkmoon_uk

    08/23/2025, 12:02 AM
    kodee loving Using a GitHub Actions pipeline? Consider using
    .kts
    files instead of Bash, to perform more complex steps; like preparing ECS Deployment tasks. The good news is - GitHub Actions images already include
    kotlin
    , so no complex preparation steps, just
    run: kotlin myScript.main.kts
    and off you go! kodee happy
    👍 4
    🎉 4
    👍🏾 1
    🙌🏼 1
    e
    n
    • 3
    • 3
  • p

    Paul Woitaschek

    09/07/2025, 5:10 PM
    What are best practices to test a main.kts script?
    m
    d
    • 3
    • 11
  • m

    mikehearn

    09/15/2025, 12:58 PM
    Is there some special rule that isn't clear for writing Kotlin Scripting IDE plugins? I find that some JARs that I return from the definition provider don't seem to be on the classpath when the compilation refiner is triggered (But some are... it's very confusing!)
    • 1
    • 2
  • m

    mikehearn

    09/15/2025, 1:54 PM
    📢 For anyone else writing a custom scripting host you might want to check out this suggestion I filed in YouTrack to swap out the default Maven Resolver bridge with some custom code that uses JBoss ShrinkWrap. It's quite easy, just requires adding two files to your codebase. This resolves a bunch of bugs that can cause weird failures in the IDE or at runtime e.g. the AWS SDK isn't usable via
    @file:DependsOn
    unless you do this because correct resolution of those artifacts requires Maven model building. There are likely other edge cases too. Please note that I didn't bother implementing any support for options as I don't use them. But it should be easy enough to see how to do it. Hope that helps!
    👀 1
    p
    • 2
    • 2
  • p

    Primoz Delopst

    09/16/2025, 9:08 PM
    Does context-parameters works with scripting?
    e
    • 2
    • 4
  • p

    Primoz Delopst

    09/26/2025, 6:36 AM
    We would like to expose code highlighting and completion via REST API for our Kotlin Scripts to be able to develop them on web. Are there any existing solutions for this?
    c
    p
    • 3
    • 13
  • y

    y9san9

    09/27/2025, 5:24 PM
    Hello. I am trying to create my own script type and I got the exception that I can't understand. More in the thread
    • 1
    • 4
  • s

    S.

    10/11/2025, 3:21 PM
    is kotlin scripting currently only supported on jvm?
    p
    i
    • 3
    • 5
  • s

    Shaun Wild

    10/24/2025, 11:37 AM
    Is Kotlin scripting defunct?
    p
    v
    m
    • 4
    • 28
  • s

    Shaun Wild

    10/24/2025, 5:38 PM
    Where would the best channel be to ask general Kotlin questions?
    v
    m
    • 3
    • 2
  • s

    Shaun Wild

    10/25/2025, 4:15 PM
    Is there something else I need here? It looks like my imports aren't being added
    e
    • 2
    • 2
  • c

    Colton Idle

    10/28/2025, 3:11 PM
    I'm trying to add a kotlin script (its in my android app project FWIW, so kotlin exists in the project), but i dont necessarily have kotlin installed on my machine directly. to use kotlin scripting do i need to install kotlin directly?
    p
    c
    • 3
    • 12
  • c

    Caleb Miles

    10/30/2025, 7:41 PM
    Hello, I am attempting to embed Kotlin scripting into a project of mine. All is well so far except for the fact that we can't use annotations with
    Copy code
    refineConfiguration#onAnnotations
    We would like to just implement the basic
    DependsOn
    ,
    Repository
    ,
    Import
    ,and
    CompilerOptions
    however whenever I specify annotations in
    onAnnotations
    I get this:
    unable to load class kotlin.script.experimental.dependencies.DependsOn.
    It seems to error on whichever annotation is first in the list. For the life of me I cannot figure this out.
    Copy code
    refineConfiguration {
            onAnnotations(DependsOn::class, Repository::class, Import::class, CompilerOptions::class, handler = AnnotationProcessor())
        }
    I can send a link to the repo if needed 🙂 Any help is much appreciated.
    e
    • 2
    • 1
  • s

    Shaun Wild

    11/01/2025, 12:50 AM
    I'm creating a game engine that makes heavy use of Kotlin scripting, but it seems like players of my game will need to have JDK installed the execute them? Is there a way around this?
    m
    • 2
    • 1
  • s

    Shaun Wild

    11/01/2025, 1:17 AM
    Also how can I go about running KTS scripts from within an IDEA plugin? I keep getting this error: Could not find installation home path. Please make sure bin/idea.properties is present in the installation directory.
    m
    • 2
    • 5
  • s

    Shaun Wild

    11/02/2025, 7:14 PM
    Other thing I noticed, where can I submit a feature/bug request? If you use the @Langauge annotation it does not work in a kts script
    m
    • 2
    • 2
  • s

    Shaun Wild

    11/02/2025, 7:15 PM
    Would be super neat if that worked
  • e

    edwinRNDR

    11/05/2025, 9:04 AM
    Is the incantation for adding script templates here documented somewhere? Having an annotated class on the cp is not enough.
    • 1
    • 3
  • e

    edwinRNDR

    11/07/2025, 10:51 AM
    How do I configure
    BasicJvmScriptingHost
    such that I can get exceptions thrown during script evaluation?
    m
    • 2
    • 3
  • d

    Draget

    11/09/2025, 12:33 AM
    I have this test.main.kts and I thought it would work, but it does not:
    Copy code
    #!/usr/bin/env kotlin
    @file:DependsOn("com.squareup.okhttp3:okhttp:5.3.0")
    import okhttp3.OkHttpClient
    println(OkHttpClient())
    Am I missing something? Thought I could define dependencies like this - but it always fails with
    Copy code
    test.main.kts:3:8: error: unresolved reference 'okhttp3'.
    import okhttp3.OkHttpClient
    e
    • 2
    • 5