https://kotlinlang.org logo
Docs
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

    Luis Munoz

    10/13/2020, 3:11 PM
    @*Ilya Cherniko I didn't see you on the talk schedule. You gotta do a talk soon*🙂
    :yes: 1
    i
    • 2
    • 3
  • w

    WukongRework.exe

    10/27/2020, 10:30 PM
    Hey guys! I’m current working on my robotics team for highschool (FTC). This year we migrated to a 100% kotlin code base and i was wondering, Am I able to create custom kts files like something.kts for an android project? I tried originally by doing the same setup as you would for a normal JVM project but I got a gradle exceeded memory error. Is there a way for this to be possible and I just set it up incorrectly or is it not possible as of right now? Thanks 🙏
    m
    n
    g
    • 4
    • 46
  • a

    Anthony Dahanne

    10/30/2020, 7:10 PM
    ^ oh noes… so Kotlin script
    Repository
    annotations does not support authentication ? everybody only pulling public artifacts ?! ^ 😣
    i
    • 2
    • 4
  • b

    bjonnh

    10/30/2020, 8:33 PM
    maybe there are ways around that?
    a
    • 2
    • 1
  • b

    bjonnh

    10/30/2020, 8:34 PM
    and it tells me that it is unable to load the JNA library (com/sun/jna/Native)
    a
    • 2
    • 4
  • k

    kenkyee

    11/06/2020, 2:26 PM
    What do folks use for an arg parser for kts scripts? Hitting this with Kotlin 1.4: https://github.com/holgerbrandl/kscript/issues/279 kscript doesn't seem to work w/ annotations so that rules out a bunch of them. Apache Commons CLI seems to work.
    m
    v
    +3
    • 6
    • 9
  • s

    SrSouza

    11/08/2020, 8:05 PM
    Hi folks, the Kotlin Main Kts supports Kotlinx.serialization ? if so, there is any example of using it?
    m
    i
    p
    • 4
    • 15
  • f

    fwilhe

    11/20/2020, 7:26 AM
    Hi. I've got a question: Is there some way to run a
    main.kts
    script without the filename ending in
    .main.kts
    ? My use-case is that I want to use Kotlin as a script interpreter on GitHub Actions. So would it be possible to make the
    kotlin foo
    line work without control of the file name? Is there some
    --run-as-script
    flag?
    ~$ cat foo.main.kts 
    #!/usr/bin/env kotlin
    println("hello")
    ~$ kotlin foo.main.kts 
    hello
    ~$ mv foo.main.kts foo
    ~$ kotlin foo
    error: could not find or load main class foo
    I've described details of what the issue is here https://github.com/actions/runner/issues/813
    v
    n
    i
    • 4
    • 19
  • s

    Slackbot

    11/23/2020, 1:17 PM
    This message was deleted.
    i
    • 2
    • 1
  • s

    Samuel Michael

    12/06/2020, 3:48 AM
    Trying to figure out how to add kotlinx.serialization plugin to kotlin scripting. Is it something like this?
    --P plugin:serialization
    Untitled
    r
    n
    b
    • 4
    • 11
  • k

    kenkyee

    12/06/2020, 3:54 AM
    You can't use it for scripting... It needs kapt...
    😅 1
    r
    • 2
    • 2
  • r

    RedTahr1

    12/08/2020, 3:17 PM
    Hi, I'm trying to lift a project from kotlin 1.3.50 to 1.4.x. Including lifting serialization. Now I got so far that it compile, but crash, And I cannot pin-point where it is wrong. I have added some debug traces to try to understand, but I get "no class found" Any idea on the way forward? For the serialization there is migration info. Has something happened with scripting same time?
    Exception in thread "main" java.lang.NoClassDefFoundError: com/intellij/openapi/util/Disposer
            at org.jetbrains.kotlin.scripting.compiler.plugin.impl.ScriptJvmCompilerIsolated.compile(ScriptJvmCompilerImpls.kt:237)
            at kotlin.script.experimental.jvmhost.JvmScriptCompiler.invoke$suspendImpl(jvmScriptCompilation.kt:30)
            at kotlin.script.experimental.jvmhost.JvmScriptCompiler.invoke(jvmScriptCompilation.kt)
            at kotlin.script.experimental.host.BasicScriptingHost$eval$1.invokeSuspend(BasicScriptingHost.kt:46)
            at kotlin.script.experimental.host.BasicScriptingHost$eval$1.invoke(BasicScriptingHost.kt)
            at kotlin.script.experimental.host.BasicScriptingHost$runInCoroutineContext$1.invokeSuspend(BasicScriptingHost.kt:35)
            at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
            at org.jetbrains.kotlin.kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
            at org.jetbrains.kotlin.kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:274)
            at org.jetbrains.kotlin.kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:84)
            at org.jetbrains.kotlin.kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
            at org.jetbrains.kotlin.kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
            at org.jetbrains.kotlin.kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
            at org.jetbrains.kotlin.kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
            at kotlin.script.experimental.host.BasicScriptingHost.runInCoroutineContext(BasicScriptingHost.kt:35)
            at kotlin.script.experimental.host.BasicScriptingHost.eval(BasicScriptingHost.kt:45)
            at <com.masking.my.class>.AtsRunner.loadAtsTest(AtsRunner.kt:543)
            at <com.masking.my.class>.AtsRunner.runTests(AtsRunner.kt:258)
            at <com.masking.my.class>.AtsRunner$Companion.main(AtsRunner.kt:168)
            at <com.masking.my.class>.AtsRunner.main(AtsRunner.kt)
    Caused by: java.lang.ClassNotFoundException: com.intellij.openapi.util.Disposer
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            ... 20 more
    • 1
    • 1
  • r

    RedTahr1

    12/16/2020, 3:41 PM
    Sorry if I repeat my questions☝️, but let me rephrase it: I'm using BasicJvmScriptingHost. It was working on kotlin 1.3.50 Now on 1.4.21 it crash.
    scriptingHost.eval(
                    sourceCode, scriptCompilationConfiguration, scriptEvaluationConfiguration
                )
    Any hint how to debug
    java.lang.NoClassDefFoundError
    or move forward?
    n
    i
    • 3
    • 7
  • v

    Vampire

    01/08/2021, 1:48 PM
    How do I prematurely end a script processing? I'm inside a Gradle Kotlin DSL script and want to stop processing. I simply tried
    return
    but it is a syntax violation. 😕
    m
    e
    • 3
    • 36
  • m

    Miguel Guilherme

    01/12/2021, 2:00 PM
    Not sure if there’s a simple way to disable the “An illegal reflective access operation has occurred” warnings. Is there a way of disabling this warnings? Kotlin Scripts seems great but this warnings are pouting the std out. Not sure how they manage to disable this but last time I use kscript this warnings were not present:
    v
    • 2
    • 17
  • z

    Zeganstyl

    01/16/2021, 8:01 AM
    Hello Is it possible to compile and run kotlin script from other (parent) script, and pass some instances/types created in parent script to child script?
    m
    e
    • 3
    • 8
  • a

    Animesh Sahu

    01/17/2021, 3:02 PM
    Is nested dependencies not getting resolved? I get
    java.lang.NoClassDefFoundError: kotlinx/atomicfu/AtomicFU
    :blob-thinking-upside-down:
    • 1
    • 1
  • v

    vineethraj49

    01/25/2021, 7:26 AM
    this may sound "full-circle", please point me to references on if I can compile a .kts to a jar with all the @file:DependsOn
    i
    h
    • 3
    • 4
  • l

    laht

    01/26/2021, 8:58 AM
    any idea how I can compile a kotlin script using API only? I already collect all the script dependencies using maven and want to package the script into a fat jar. I only need to compile the script itself so I can throw it into a Jar.
    n
    • 2
    • 5
  • l

    laht

    02/01/2021, 1:36 PM
    It appears .main.kts uses a different way to resolve maven deps than
    kotlin-script-examples
    jvm-embeddable-host
    . Why is that? The latter is able to resolve dependencies fully, whereas main.kts does not (even with runtime option). E.g. lwjgl3 (opengl) will fail during runtime with main.kts, but not using the jvm-embeddable-host
    m
    i
    • 3
    • 5
  • m

    mbonnin

    02/02/2021, 12:42 PM
    Speaking of resolvers, can I use BOMs in *.main.kts file ? Something like
    @file:DependsOn("com.google.cloud:libraries-bom:16.3.0")
    @file:DependsOn("com.google.cloud:google-cloud-speech")
    Looks like I can't but I'm curious if there's a way to make this work?
    l
    • 2
    • 5
  • p

    pgreze

    02/04/2021, 8:07 AM
    Also, is there a way to detect that a given script is the entry-point? In Python you can use:
    if __file__ == "__main__": hello("sample")
    My use case is when using the @\Import feature. Let’s imagine script1.main.kts:
    @file:Import("script2.main.kts")
    
    hello("john")
    and script2.main.kts:
    fun hello(name: String) = TODO(...)
    
    // MAIN start
    hello("sample") // executed even when imported
    // MAIN end
    👀 5
    n
    • 2
    • 4
  • r

    Rodrigo Graciano

    02/07/2021, 8:49 PM
    I tried few different things as the one below but no luck From the SB app
    val engine = ScriptEngineManager().getEngineByExtension("main.kts")!!
    engine.put("jdbcTemplate",jdbcTemplate)
    engine.eval("""@file:Import("/test.kts")""".trimIndent())
    From the test.kts script
    val template = bindings.get("jdbcTemplate")
    i
    • 2
    • 4
  • m

    mbonnin

    02/09/2021, 10:02 AM
    Does .main.kts support resolving transitive dependencies ? In
    @file:DependsOn()
    annotations ? I have some weird cases where it looks like it doesn't.
    v
    a
    +2
    • 5
    • 28
  • i

    igor.wojda

    02/23/2021, 12:45 PM
    How can I call cmd from Kotlin script and store result/output in the variable?
    m
    p
    y
    • 4
    • 6
  • i

    igor.wojda

    02/23/2021, 12:46 PM
    How to open webpage (in default browser) directly from Kotlin script?
    m
    • 2
    • 2
  • r

    Rodrigo Graciano

    02/23/2021, 11:54 PM
    What are the limitation in using Kotlin Script? e.g. if I call a regular kts(not a main.kts), from a Kotlin application does it have access to everything from the app that invoked the script (classes/methods)?
    n
    i
    • 3
    • 3
  • g

    gianluz

    03/01/2021, 9:39 PM
    Hello everyone and @ilya.chernikov!! I have a case where i need to see working a
    .main.kts
    script with a compiled jar runtime locally inside IntelliJ and in CI. More in specific: • i have a project where i compile a module with this jar that is going into:
    build/libs/myJar.jar
    • then i have a
    MyScript.main.kts
    where i use the library:
    @file:DependsOn("./build/libs/test-jar-main-kts-0.1.jar")
    
    import com.test.jar.TestJar
    
    print(TestJar.iAmTestJar())
    If i run the script from IntelliJ works but the script gives an error :
    File build/libs/myJar.jar
    not found and i cannot benefit the autocomplete. By using the
    /absolute/path/to/myJar.jar
    it works well in IntelliJ with autocomplete and locally in general, but the path will be different whiles running on CI or another machine. Is there a way to have this working well both locally and on CI/other machine just using relative paths? Alternatively, how i can contribute to fix that? attached a screenshot
    i
    • 2
    • 1
  • a

    altavir

    03/09/2021, 6:23 AM
    Is JVM-IR already supported for scripting? I had some problems running JVM-IR code from kotlin-jupyter (as always, it is serialization runtime). And JVM-IR is almost the default now.
    i
    p
    i
    • 4
    • 14
  • j

    Jakub Gwóźdź

    03/11/2021, 6:31 PM
    Hi. As soon as I start kotlinc (installed by sdkman) I'm greet with warnings I don't know how to get rid of:
    ➜  local git:(develop) ✗ kotlinc
    OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
    WARNING: An illegal reflective access operation has occurred
    WARNING: Illegal reflective access by com.intellij.util.ReflectionUtil to method java.util.ResourceBundle.setParent(java.util.ResourceBundle)
    WARNING: Please consider reporting this to the maintainers of com.intellij.util.ReflectionUtil
    WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
    WARNING: All illegal access operations will be denied in a future release
    Welcome to Kotlin version 1.4.31 (JRE 15.0.1+9-18)
    Type :help for help, :quit for quit
    -nowarn
    does not change a thing. How do I mute these warnings? I'm running my scripts with
    #!/usr/bin/env kotlinc -script
    shebang I don't really care if the warnings stays or are solved, I just don't want to see them on the screen
    i
    • 2
    • 2
Powered by Linen
Title
j

Jakub Gwóźdź

03/11/2021, 6:31 PM
Hi. As soon as I start kotlinc (installed by sdkman) I'm greet with warnings I don't know how to get rid of:
➜  local git:(develop) ✗ kotlinc
OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.intellij.util.ReflectionUtil to method java.util.ResourceBundle.setParent(java.util.ResourceBundle)
WARNING: Please consider reporting this to the maintainers of com.intellij.util.ReflectionUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Welcome to Kotlin version 1.4.31 (JRE 15.0.1+9-18)
Type :help for help, :quit for quit
-nowarn
does not change a thing. How do I mute these warnings? I'm running my scripts with
#!/usr/bin/env kotlinc -script
shebang I don't really care if the warnings stays or are solved, I just don't want to see them on the screen
i

ilya.chernikov

03/11/2021, 8:14 PM
https://youtrack.jetbrains.com/issue/KT-43520 unfortunately there is no generic workaround, until the core problem is fixed.
j

Jakub Gwóźdź

03/12/2021, 7:32 AM
thanks!
View count: 15