https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
scripting
  • l

    louiscad

    08/23/2021, 2:28 PM
    Follow-up question: where is the script cache located? I'd like to not pay the price of compilation each time (which is measured in tens of seconds).
    ✅ 1
    m
    • 2
    • 7
  • a

    Achifal

    08/26/2021, 10:41 AM
    Hi! Assuming I run my script.main.kts file from a directory different than the directory where the script resides, e.g. with 
    kolinc -script /path/to/script
    , is there a way to get the location of the script file at runtime? It's extremely needed for convenient usage of Kotlin for scripting use cases. Thanks
    m
    • 2
    • 1
  • s

    Su5eD

    09/02/2021, 9:19 AM
    Is it possible to limit java classes accessible from scripts to specific packages?
    i
    • 2
    • 5
  • s

    SrSouza

    09/09/2021, 6:49 PM
    Hi folks, any news on support for suspend scripts ?
    i
    • 2
    • 1
  • s

    smallshen

    09/12/2021, 5:47 PM
    What causes this? when I remove api import for the script-definition, it resolves different
    i
    • 2
    • 3
  • e

    elect

    09/14/2021, 10:11 AM
    I'm working atm on some bash scripts for HPC and I'm really sad on typing bash syntax in a text editor in 2021, so I thought about kotlin. I'd like to write some small kotlin wrapper for Slurm (the state-of-the-art Api for managing tasks on HPC). What would you suggest? I'm pretty new to kotlin scripting.. Creating a lib and then users shall just
    dependsOn
    from within the scripts?
    b
    m
    • 3
    • 43
  • e

    elect

    09/14/2021, 10:16 AM
    also, what about kotlin scripting without any jvm?
    s
    m
    • 3
    • 29
  • e

    elect

    09/14/2021, 8:26 PM
    if I want to execute a shell command (and parse manually what it prints out) in a kotlin script file, what are my options? I saw kotlin-shell, but I couldnt understand how to read the output, or Turtle, which looks simpler (but I didn't try it yet)
    m
    p
    • 3
    • 4
  • k

    Kareem Radwan

    09/15/2021, 11:53 AM
    Hi there why I get this exception while I use 
    ignoreUnknownKeys
     and 
    coerceInputValues
     ?!
    i
    • 2
    • 2
  • a

    altavir

    09/15/2021, 2:15 PM
    Not sure why it is not here: https://t.co/D3eCNBBN78?amp=1
    :thank-you: 5
    e
    • 2
    • 2
  • s

    Su5eD

    09/18/2021, 8:07 PM
    After adding a dependency with a custom script definition, syntax highlighting in gradle.kts files breaks. Has anyone come across this before? Should I file an issue?
    e
    • 2
    • 1
  • a

    Alexey Subach

    09/19/2021, 11:15 PM
    Hi, this is a follow up on https://kotlinlang.slack.com/archives/C0BUHC9HD/p1630176850004300 (and https://youtrack.jetbrains.com/issue/KT-48414 - support for obtaining script file location) It wasn't super clear to me how to implement this initially, but after clarification in https://github.com/Kotlin/KEEP/issues/75#issuecomment-908723404 I was able to get something that works. The approach I was trying to implement was to support the following declarations in the script:
    @file:ScriptFileLocation("scriptFileLocation")
    
    scriptFileLocation.absolutePath
    The commit with the changes is available here: https://github.com/Snipx/kotlin/commit/339500282347811f269e8d67d053af5991ba813b Would it be possible to give me some feedback around that initial approach? Or should I submit a PR and continue the discussion there?
    👍 1
    i
    • 2
    • 15
  • e

    elect

    09/20/2021, 11:04 AM
    what about interactivity, ie executing shell commands with
    sudo
    where I have to type the pwd? Shall I directly execute the script itself with
    sudo
    ?
    m
    e
    • 3
    • 13
  • r

    Rob Elliot

    10/11/2021, 3:44 PM
    Is there a way to guarantee that a script is pure? So it has zero side effects and just returns a value? My idea is that Kotlin is expressive enough to write typesafe configuration files directly in it - so an application could specify a data class or interface representing its config, and then configurers can write a
    .kts
    file that returns an instance of that type, and by setting up their IDE to have the classpath available then they will find out when configuring it whether or not their configuration will compile, and the application can gain compilation validation of its config by evaluating the file. But that means evaluating code that could theoretically do anything. I’ve implemented it using JSR-223 & a
    SecurityManager
    to try and prevent unwanted execution here: https://gist.github.com/Mahoney/8979e520b7477c9a9771fe3e1da3472a but it feels a bit clunky, and the
    SecurityManager
    is deprecated in Java 17 for removal in future Java releases. As I’ve just found out that Kotlin has its own scripting API, I wondered if it could be run in such a way?
    v
    i
    e
    • 4
    • 4
  • s

    Su5eD

    10/15/2021, 8:12 PM
    I'm not sure if this has been reported before, but attempting to print the evaluation result of
    BasicJvmScriptingHost#eval
      will result in a
    StackOverflowError
    when
    scriptsInstancesSharing
    is enabled. Can't find any similar issues on YT so might as well go ahead and make one
    i
    • 2
    • 1
  • g

    George Ciubotaru

    10/21/2021, 10:13 AM
    Hello, I'm using JSR-223 to evaluate a script. After evaluation I want to get the variables declared in that context but I don't seam to be able to. All I can get are the variables that I've manually added to the engine (with
    ScriptEngine.put()
    method) and 2 internal variables:
    kotlin.script.engine
    &
    kotlin.script.state
    . Is there a way to get the variables declared within the script?
    i
    • 2
    • 6
  • s

    starke

    10/23/2021, 12:19 AM
    Hi! I’m encountering an issue with
    @file:Import
    when running a script in the IDE. Getting this error when trying to add
    @file:Import("script1.main.kts")
    to
    script2.main.kts
    error: backend Internal error: Exception during IR lowering
    File being compiled: development/script1.main.kts
    The root cause java.lang.RuntimeException was thrown at: org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate(FunctionCodegen.kt:50) (script2.main.kts): org.jetbrains.kotlin.backend.common.BackendException: Backend Internal error: Exception during IR lowering
    File being compiled: development/script1.main.kts
    The root cause java.lang.RuntimeException was thrown at: org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate(FunctionCodegen.kt:50)
    I saw this thread that suggested using
    useOldBackend
    until the bug is fixed, but I couldn’t figure out how to set this flag when running the script in the IDE. It also mentioned that the bug might be fixed in the kotlin 1.6 release, but I can’t find any documentation about how to specify the kotlin version for a
    kotlin-main-kts
    script 🤔 I wanted to try Kotlin 1.6.0-RC to see if the bug disappears, but I’m not sure how to define the script’s kotlin version. Thanks in advance!
    b
    n
    • 3
    • 3
  • b

    breandan

    10/29/2021, 5:11 AM
    I tried KTS for the first time in a while today. It worked reasonably well. Although I could create the
    *.kts
    file and run it, code completion, static analysis and importing did not work properly on IU-2021.3 and I didn’t bother to figure out why. Doesn't the IDE bundle it's own JDK? Scripting support should work out of the box on every project with zero configuration required.
    m
    • 2
    • 2
  • e

    elect

    11/05/2021, 12:20 AM
    whenever I try to call a top level function in an imported script, I get:
    error: backend Internal error: Exception during code generation
    File being compiled: /home/elect/IdeaProjects/incubator/scijava/scijava-function/templates/main/java/org/scijava/function/Computers.main.kts
    The root cause java.lang.RuntimeException was thrown at: org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate(FunctionCodegen.kt:50) (Computers.main.kts): org.jetbrains.kotlin.backend.common.BackendException: Backend Internal error: Exception during code generation
    File being compiled: /home/elect/IdeaProjects/incubator/scijava/scijava-function/templates/main/java/org/scijava/function/Computers.main.kts
    The root cause java.lang.RuntimeException was thrown at: org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate(FunctionCodegen.kt:50)
    r
    n
    • 3
    • 5
  • d

    dector

    11/23/2021, 3:20 PM
    Hi! I was using kscript before but since it's not migrated to Kotlin 1.5 I've decided to try native Kotlin scripting. Question is: do we have proper IDE support or it's completely broken yet? When I'm opening
    .main.kts
    script in IDEA I have such issues: • JDK is not found (
    import java.*
    not recognized) even when I'm selecting proper JDK version manually in module settings. • Auto-completion doesn't work for classes included with
    @file:DependsOn()
    . Is this expected behavior? Thanks.
    m
    h
    a
    • 4
    • 8
  • s

    Sebastian Schuberth

    12/21/2021, 8:45 PM
    Hi all, I'm having trouble getting code completion in IntelliJ to work with my custom Kotlin scripts. After reading through https://github.com/Kotlin/KEEP/blob/master/proposals/scripting-support.md#how-to-implement-scripting-support I've added a
    .classpath
    file to my project's
    META-INF
    directory, but it seems I also need to add my project's JAR now to the compiler's classpath. How do I actually do that from the IDE? My code changes can be seen at https://github.com/oss-review-toolkit/ort/pull/4887/files#diff-b5d75d77219b5108e66671916d8001890961d0063bbff4e606b13d286374908e.
    b
    • 2
    • 4
  • a

    adryan_ip

    12/25/2021, 2:45 PM
    Only for increasing visibility of the question 😅 https://kotlinlang.slack.com/archives/C0BT46EL8/p1640443392042500?thread_ts=1637680809.032200&cid=C0BT46EL8
    a
    i
    • 3
    • 2
  • h

    holgerbrandl

    12/28/2021, 5:38 PM
    Is there a reason why
    const
    is not supported in scripts?
    i
    m
    • 3
    • 5
  • p

    Piotr Krzemiński

    01/12/2022, 7:20 AM
    the snap for Kotlin is still on 1.6.0 while we have 1.6.10 now, it's a month old. 1.6.10 apparently has a fix for a bug relevant in scripting. Looks like this is officially released by JetBrains - https://snapcraft.io/kotlin. The same with SDKman. Could someone update it, and even better: keep it in sync with actual releases? 🙂
    ☝️ 1
    i
    m
    • 3
    • 3
  • h

    holgerbrandl

    01/12/2022, 8:27 PM
    Is there YouTrack ticket pointing out the headless-inconsistency between kt and kts? kts is somehow internally configured to be headless, whereas kt is not. I don't understand why the script tooling is opinionated here about what a user may want to code in a kts. Script example:
    import javax.swing.JOptionPane
    
    JOptionPane.showMessageDialog(null, "kotlin script, show yourself! ");
    which fails
    java.awt.HeadlessException
    	at java.desktop/java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:208)
    	at java.desktop/java.awt.Window.<init>(Window.java:548)
    	at java.desktop/java.awt.Frame.<init>(Frame.java:423)
    	at java.desktop/java.awt.Frame.<init>(Frame.java:388)
    	at java.desktop/javax.swing.SwingUtilities$SharedOwnerFrame.<init>(SwingUtilities.java:1919)
    	at java.desktop/javax.swing.SwingUtilities.getSharedOwnerFrame(SwingUtilities.java:1995)
    • 1
    • 1
  • s

    Sebastian Schuberth

    01/12/2022, 9:14 PM
    Is there a way to dynamically add class properties (that are not present in the template class) within a
    createJvmCompilationConfigurationFromTemplate
    lambda block, similar to like in JSR223 I can do
    engine.put("name", value)
    ?
    i
    • 2
    • 4
  • n

    nfrankel

    01/15/2022, 9:00 AM
    with the same script, it works as expected in kotlin 1.4 and fails in kotlin 1.6 with a method not found on jsoup?! which is completely unexpected i’ve no clue why any hint?
    h
    r
    • 3
    • 9
  • c

    Craig

    01/26/2022, 10:25 AM
    I've implemented a custom
    @KotlinScript
    . Works great, using
    BasicJvmScriptingHost
    inside a command line app. I would like a good developer experience too, so I've started an IDEA plugin, using
    ScriptDefinitionsProvider
    which is also sort of working. Is it possible to run and debug this script in IDEA? I have no idea how to go about supplying the implicit receiver objects required by the script context. Also, is it possible to supply javadocs to the configuration?
    ScriptDefinitionsProvider.getDefinitionsClassPath
    suggests not. Thanks.
    i
    • 2
    • 2
  • s

    SrSouza

    01/29/2022, 11:59 PM
    I always use
    kotlin
    command line to run
    main.kts
    scripts, there is anyway to use the IntelliJ embedded Kotlin to run
    main.kts
    scripts? I don't want to make everyone from the team install Kotlin in their machines.
    👀 1
    y
    i
    • 3
    • 2
  • v

    vpriscan

    02/03/2022, 8:47 AM
    I have found a bug in Kotlin JSR-223 implementation. When you want to precompile a script with bindings, you have to add bindings to engine scope first, which is ok. Later, when evaluating script with compiledScript.eval(bindings), Kotlin JSR-223 engine ignores those new bindings, and uses the ones from engine scope. I run multiple scripts in multiple threads sharing the same engine instance, using shared bindings from engine scope is not thread safe.
    i
    • 2
    • 2
Powered by Linen
Title
v

vpriscan

02/03/2022, 8:47 AM
I have found a bug in Kotlin JSR-223 implementation. When you want to precompile a script with bindings, you have to add bindings to engine scope first, which is ok. Later, when evaluating script with compiledScript.eval(bindings), Kotlin JSR-223 engine ignores those new bindings, and uses the ones from engine scope. I run multiple scripts in multiple threads sharing the same engine instance, using shared bindings from engine scope is not thread safe.
i

ilya.chernikov

02/03/2022, 10:27 AM
Please report the bug to Kotlin YouTrack. But I strongly recommend you to stop sharing an engine between threads. The kotlin engine keeps (in the engine scope bindings) the state of the compilation and evaluation, and although there is some locking in place, so it should not blow up, you may see some things leaking from one script to another. And compilation will be serialized anyway. If you're trying to have thread-specific bindings, then (after the problem you found will be fixed) the state will be separate too, so you'll not get any performance benefits from sharing the engine. So it seems to me that by having separate engine for every thread will solve your problem and will be more robust overall.
👍 1
v

vpriscan

02/14/2022, 4:13 PM
I understand, thank you
View count: 7