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
  • e

    elect

    07/14/2022, 4:52 AM
    I see that the docs suggest to have two modules, "host" and "script-definition":
    With all of this in mind, it’s best to split the project into two modules.
    while in the example of Oliveira mentioned above he has definition and host inside one single module. And the same is the
    simple-main-kts
    inside "kotlin-script-examples". Is there any specific reason to have them splitted?
    i
    • 2
    • 1
  • e

    elect

    07/14/2022, 7:10 AM
    I noticed that running the script via
    main
    (as suggested by docs) then the evaluation and configuration gets called. If I try using the IDE instead, no. Is this expected? Do I have to do something special for the Idea to recognize them? (ie meta-inf)
    i
    • 2
    • 9
  • e

    elect

    07/14/2022, 8:04 AM
    is it possible to pass arguments to the script class (that with
    @KotlinScript
    )? Looking at the code I don't think so 😕
    • 1
    • 1
  • e

    elect

    07/14/2022, 4:43 PM
    is there a chance for the host to retrieve the instance of the script class after the script execution/evaluation?
    v
    i
    • 3
    • 5
  • e

    elect

    07/18/2022, 12:24 PM
    so, I've tried to run one of the
    smain.kts
    scripts in "kotlin-script-examples" by running the scripts itself (right click -> Run), but I get:
    warning: default scripting plugin is disabled: The provided plugin org.jetbrains.kotlin.scripting.compiler.plugin.ScriptingCompilerConfigurationComponentRegistrar is not compatible with this version of compiler
    error: unable to evaluate script, no scripting plugin loaded
    i
    • 2
    • 3
  • e

    elect

    07/19/2022, 9:02 AM
    I cant find any
    @ScriptBody
    annotation
    i
    • 2
    • 3
  • p

    Piotr Krzemiński

    07/20/2022, 7:04 AM
    No traction with Dependabot, let's try Renovate: https://github.com/renovatebot/renovate/issues/16662 - if they agree to add support for it, I'm keen to implement it
    • 1
    • 3
  • e

    elect

    07/20/2022, 9:40 AM
    two observations: •
    scriptBodyTarget
    doesn't exist, probably a relict or to be implemented • unless I explicitly force the superclass by defining
    baseClass
    , the script class doesn't seem to implement the Script class defined by
    @KotlinScript
    val res = evalFile(File("$TEST_DATA/hello-resolve-junit.tf.kts"))
            val inst = res.valueOrThrow().returnValue.scriptInstance!! as Script
            println(inst.pro2) // works only with baseClass(Script::class)
  • j

    Javier

    07/20/2022, 11:38 AM
    I am picking a dependency from Sonatype snapshot repo and looks like it is cached and it is not replaced with the new artifact, I am forced to indicate the date or is there a way to force to update it?
    m
    h
    • 3
    • 10
  • e

    elect

    07/20/2022, 4:35 PM
    I have some scripts where code highlighting is broken (that is off), others where it works any tips how to trigger/fix those?
  • a

    andylamax

    07/26/2022, 1:12 PM
    is
    @file:Imports
    still not supported by IDE?
    b
    p
    • 3
    • 3
  • e

    ESchouten

    07/26/2022, 1:24 PM
    https://twitter.com/martinbonnin/status/1551907653949034497
    p
    m
    • 3
    • 4
  • j

    jmfayard

    07/30/2022, 3:07 PM
    really cool tools for glamorous shell scripts 🎀 is there something similar in Kotlin or should I just call the go executable? https://github.com/charmbracelet/gum
    m
    • 2
    • 2
  • j

    jmfayard

    07/31/2022, 5:15 PM
    Bonjour, how do you distribute on multiple platforms a CLI tool written with Kotlin-native? Last time I checked it was easier to publish via Kotlin-JS on npm... Or do you use your custom brew tap? EDIT: discussion happens here https://kotlinlang.slack.com/archives/C3SGXARS6/p1659287684467169https://kotlinlang.slack.com/archives/C3SGXARS6/p1659287684467169
  • j

    jmfayard

    08/01/2022, 6:43 AM
    Bonjour again, do you have a way to combine scripting and unit testing? Like if I have pure functions or a Regex inside my script, I would like to be able to unit test it so that the script itself is only a small imperative shell around the functional core
    b
    • 2
    • 8
  • a

    altavir

    08/18/2022, 9:55 AM
    Look, here is proof-of concept gradle-like API for declaring dependencies for Jupyter Kernel: https://github.com/Kotlin/kotlin-jupyter/pull/382. I think I would like something like this for general scripting as well. The aim is to unify the way dependencies are loaded in different environments. There is a problem though. Regular script does not have staged compilation, so either one needs to use gradle-like hacks with ahead-of-time block evaluation, or a separate file with dependencies.
    i
    • 2
    • 2
  • j

    jmfayard

    08/23/2022, 3:22 AM
    Bonjour, I have a Kotlin script that I need to run on heroku (gradle buildpack) but I have no idea how to do
    sdk install kotlin
    or
    snap install kotlin
    on heroku and Google isn't my friend either. Any idea?
    v
    b
    • 3
    • 14
  • h

    holgerbrandl

    08/27/2022, 4:45 PM
    We've published kscript v4.1 just today with great new features listed in https://github.com/holgerbrandl/kscript/blob/master/NEWS.md#410…. Let's forget about bash, let's kotlin in the shell! Almost all kudos for this release go to @KuszczakMarcin who's also taking over the lead in the project.
  • r

    ribesg

    09/02/2022, 2:43 PM
    Where do compiled scripts caches go? I need to clean it but can't find info about it
    • 1
    • 1
  • m

    mikehearn

    09/05/2022, 2:08 PM
    That happens if the Kotlin script definition isn't found or can't be loaded. It can happen for several reasons. Try looking in the IDEA log files to see what is happening, there is usually a message explaining why. If you don't see anything at all it means it's not being registered.
    p
    • 2
    • 3
  • n

    Nikky

    09/05/2022, 7:56 PM
    i have big issues with
    .main.kts
    files recently, freezing the IDE, especially bad when there is something invalid in the
    @DependsOn
    or such fixes itself if i somehow manage to close the file though..
    i
    • 2
    • 2
  • p

    Peter

    09/08/2022, 5:25 AM
    Does anyone know of a way to run untrusted scripts with a certain level of isolation so they cannot do too much harm? Currently looking into firecracker, but if it can be done in-process that would be much easier.
  • s

    Sebastian Schuberth

    09/19/2022, 6:11 PM
    Can someone explain to me what's the difference between the
    kotlinScriptDef
    and
    kotlinScriptDefExtensions
    Gradle configurations, and which to use when?
    i
    • 2
    • 5
  • v

    Vampire

    09/26/2022, 12:45 PM
    Interesting, according to the docs it is still experimental
    m
    a
    • 3
    • 5
  • z

    zt

    10/09/2022, 5:57 PM
    I have a kotlin native project, could I somehow add support for scripts?
    b
    • 2
    • 1
  • h

    humblehacker

    10/13/2022, 2:10 AM
    I'm just getting started using kscript, and I'm trying to use
    runCommand()
    from kscript-tools. Anyone familiar with this? I've added the dependency to my script:
    @file:DependsOn("com.sealwu:kscript-tools:1.0.2")
    and I've added a line to my script to test it:
    "ls".runCommand()
    But when I run the script,
    runCommand()
    can't be found:
    error: unresolved reference: runCommand
    If I run the script from IDEA using
    kscript --idea myscript.kts
    it works fine. It's only when I run the script from the command line that it fails. Anyone have any idea what I'm doing wrong?
    b
    • 2
    • 3
  • s

    Sebastian Schuberth

    10/13/2022, 8:00 AM
    After upgrading to Kotlin 1.7.20 I started to get
    w: Script 'osadl.rules.kts' is not supposed to be used along with regular Kotlin sources, and will be ignored in the future versions by default. (Use -Xallow-any-scripts-in-source-roots command line option to opt-in for the old behavior.)
    for a script that's committed as a resource in a Kotlin project (see https://github.com/oss-review-toolkit/ort/blob/osadl-rules/evaluator/src/main/resources/rules/osadl.rules.kts). What's this supposed to tell me? I mean, the script is not in a source root of Kotlin source set after all...
    b
    • 2
    • 14
  • r

    rnett

    10/15/2022, 3:01 AM
    I'd like to have a script def that treats the script as if it is an object/class body instead of a method body. Is this possible at the moment? Could I achieve it via a compiler plugin (probably not much point in going there until K2)? Is there a currently tracked issue for it?
    i
    • 2
    • 5
  • z

    zt

    10/18/2022, 7:45 PM
    Would compose-jb work with scripting?
    m
    b
    +2
    • 5
    • 10
  • a

    Adam S

    11/06/2022, 1:30 PM
    I've written a .main.kts script using Ktor server and client, but the logging doesn't work. I only get output for
    println()
    , and also the Micrometer dependency prints something
    ➜  kts-px /Users/me/projects/kts-px/px.main.kts
    Nov 06, 2022 2:29:49 PM io.micrometer.core.instrument.push.PushMeterRegistry start
    INFO: publishing metrics for LoggingMeterRegistry every 1m
    I've tried with logback-classic and slf4j-simple, but I can't figure it out... any ideas?
    • 1
    • 4
Powered by Linen
Title
a

Adam S

11/06/2022, 1:30 PM
I've written a .main.kts script using Ktor server and client, but the logging doesn't work. I only get output for
println()
, and also the Micrometer dependency prints something
➜  kts-px /Users/me/projects/kts-px/px.main.kts
Nov 06, 2022 2:29:49 PM io.micrometer.core.instrument.push.PushMeterRegistry start
INFO: publishing metrics for LoggingMeterRegistry every 1m
I've tried with logback-classic and slf4j-simple, but I can't figure it out... any ideas?
px.main.kts.txt
I've tried a few different combinations of slf4j, logback, and versions
I guess the main.kts JAR embeds slf4j-nop? https://github.com/JetBrains/kotlin/blob/fbb0d6d805894dc0915faee7dbf28d8e1e581efd/libraries/tools/kotlin-main-kts/build.gradle.kts#L40 why?
I made an issue https://youtrack.jetbrains.com/issue/KTIJ-23533
View count: 8