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

    tapchicoma

    03/24/2019, 12:48 PM
    https://github.com/Tapchicoma/ktsexec-gradle -
    KtxExec
    task that, for now, supports only simple scripts (jcenter approval is pending)
    ➕ 3
    n
    e
    • 3
    • 27
  • e

    efemoney

    03/30/2019, 3:40 AM
    Can we have a more sophisticated way for kotlin scripting to filter classpath files say by regex instead of the exact jar/file name. Or if full regex is not possible just support for wildcard (
    *
    ). The issue I’m facing is that in AS, with gradle, I have a service-def (script definitoin) module and a services (actual script files in src folder) module. The services module gets its dependencies via gradle project dependencies (currently
    project(":service-def")
    ,
    project(":service-api")
    and
    project(":service-dsl")
    plus kotlin-stdlib and scripting-jvm dependencies). I also have a service-host module which I use to run the scripting host to debug issues and test out the scripts. I really want to be able to specify only required jars while building the compilation configuration (only the api and dsl jars/classes should be visible within the scripts) but I cannot do this because, when resolved from intelliJ/AS, the classpath contains the actual jars like
    service-api-dev.jar
    , but when I run the host module java app, the classpath contains folders with
    .class
    files like
    .../api/build/classes/main/
    . I think its a Gradle performance feature to avoid building the actual jars in the case of project dependencies. Would be great if I could specify
    *api*
    and
    *dsl*
    to filter the classpath as that would cover all the cases. Current workaround is to use
    dependenciesFromCurrentContext(wholeClasspath = true)
    which works but I dunno if I like. Also, the requirement for the jar version is too strict. As you can see from above my current version is dev because project is still in development. The current classpath filtering tries to strictly match semver like x.y.z and filters out my correct jars. Final question: does scripting add the kotlin stdlib dep automatically? aka if I wanted a really small classpath, can I specify only api and dsl jars w/o explicitly specifying the stdlib and it will work? (My guess is no and we would have to add a kotlin compile config to compile with the stdlib or else specify it) Final question 2: what classpath does the kotlin IJ/AS plugin use to determine dependencies for scripts? Like, if I open a custom script how is IJ/AS able to know the correct types. I know I have to have a jar in the classpath that contains script definition (in my case, I have to make sure to assemble/build the service-def module) but what classpath is IJ/AS checking exactly
    i
    • 2
    • 4
  • t

    tapchicoma

    04/01/2019, 6:30 PM
    Short update on https://github.com/Tapchicoma/ktsexec-gradle: - finally published to JCenter (should be already available) - added no-op Gradle plugin (pending approval)
    e
    • 2
    • 1
  • a

    Andrew Gazelka

    04/10/2019, 3:19 PM
    is there a built-in way for me to have multiple
    kts
    scripts linked together or would I be better off using
    kscript
    ?
    g
    • 2
    • 2
  • a

    Andrew Gazelka

    04/10/2019, 3:20 PM
    additionally, are Kotlin scratches stable enough to be an alternative to Nashorn for the reason of having interpreted code instead of compiled? (for the purpose of hot swapping)
    g
    • 2
    • 13
  • s

    sdeleuze

    04/12/2019, 9:42 AM
    -.txt
    i
    • 2
    • 8
  • s

    sdeleuze

    04/12/2019, 11:08 AM
    -.txt
    i
    • 2
    • 23
  • s

    sdeleuze

    04/12/2019, 11:10 AM
    Is there any workaround for this one? Any chance to release 1.3.31 short term to fix these issues?
    l
    • 2
    • 1
  • a

    altavir

    04/13/2019, 9:54 AM
    I am trying to migrate beakerx kotlin evaluator to scripting from REPL engine. So I will probably have a lot of questions. First one: is there a way to determine current kotlin compiler version from inside the program?
    i
    • 2
    • 16
  • a

    altavir

    04/13/2019, 10:56 AM
    Another question: I need the last statement in script to be returned as result. Is it possible to do it?
    i
    s
    d
    • 4
    • 13
  • a

    altavir

    04/14/2019, 5:19 PM
    I've created a ticket for explicit script dependencies declaration: https://youtrack.jetbrains.com/issue/KT-31021. I do not have a clear idea about such declarations, but I think we really need them, otherwise tooling for script writing seems to be very unstable.
    g
    • 2
    • 88
  • s

    SrSouza

    04/19/2019, 4:16 AM
    Hi @ilya.chernikov, I try to create a inline class in a script and not work, this is normal or a bug?
    i
    • 2
    • 1
  • s

    Slackbot

    04/19/2019, 7:58 PM
    This message was deleted.
    :google: 2
    l
    g
    • 3
    • 2
  • d

    DALDEI

    05/05/2019, 6:32 PM
    Copied from #intellij --> I've tried every trick I have found documented and many I have not to get Intellij kotlin "script" to interop properly with Java 1.8. Whether in REPL or in a scratch if its a '.kts' the exact same code that works for .kt files fails with .kts files when I use an inline function that was compiled using jvm 1.8 (as ALL my settings and projects specify). The complaint is the well known "cant use inline bytecode from 1.8 when compiling into 1.6 bytecode pleas use -jvm-target" -- but from inside intellij you cant specify it (I tried -- ,as well as all the settings, facets, hand-editing the .iml files etc no go. Take the exact same .kts file and rename it to ".kt" works fine. Looking in the kotin compiler source doesnt seem to be another global way to fix this -- its got to be passed down through intellij somewhere -- I've put ever variant I can find in my gradle scripts to no affect. My conclusion is that kotlin script compilation doesnt follow the same paths as kotlin compiling. Any suggestions ?
    i
    • 2
    • 8
  • a

    amanda.hinchman-dominguez

    05/29/2019, 4:57 AM
    Ran into something unfortunate… I’ve transferred my TornadoFX project to use OpenJDK11 and OpenJFX, but upon starting the KotlinCoreEnvironment for PSI parsing, it appears that it is also trying to read the openJDK modules… it seems to care about the JDK modules being used in my project but I’m not sure if it’s trying to read the modules in my VM settings or what
    l
    n
    • 3
    • 10
  • a

    amanda.hinchman-dominguez

    05/29/2019, 9:55 PM
    Gradle: 4.8
    Kotlin: 1.3.21
    jonrengleman.shadow: 4.0.2
    JDK: ZuluJDK8
    n
    l
    • 3
    • 24
  • l

    Lorin

    05/30/2019, 9:25 AM
    I might find a bug in kotlin-scripting (v1.3.31). The code is as follows:
    @KotlinScript(fileExtension = "simplescript.kts")
    abstract class SimpleScript
    
    fun main() {
        val config = createJvmCompilationConfigurationFromTemplate<SimpleScript> {
            jvm {
                dependenciesFromCurrentContext(wholeClasspath = true)
            }
        }
    
        val s = """
            println("This is a test!")
        """.trimIndent()
    
        val res = BasicJvmScriptingHost().eval(s.toScriptSource("script-name"), config, null)
        println(res)
    }
    Running this program, the following error is reported:
    Failure(reports=[ScriptDiagnostic(message=Not a script file, severity=ERROR, sourcePath=null, location=null, exception=null)])
    But if I remove the argument
    "script-name"
    from
    s.toScriptSource()
    . Everything will be fine. Could anyone from JB confirm it? Thanks!
    a
    i
    • 3
    • 4
  • c

    cedric

    05/30/2019, 7:20 PM
    Any thought why the following cannot resolve the dependency?
    // a.kts
    @file:org.jetbrains.kotlin.script.util.DependsOn("junit:junit:4.11")
    org.junit.Assert.assertTrue(true)
    Then:
    $ kotlinc -classpath ~/.kobalt/cache/org/jetbrains/kotlin/kotlin-script-util/1.3.31/kotlin-script-util-1.3.31.jar a.kts
    a.kts:3:5: error: unresolved reference: junit
    org.junit.Assert.assertTrue(true)
        ^
    $
    t
    • 2
    • 2
  • i

    ilya.chernikov

    05/31/2019, 3:26 PM
    @cedric There are several ways to get a scripting engine with customizations (including classpath), depending on your needs. All of them require some coding so far, and there is still almost no documentation, but in fact this is not too difficult. See the thread below for some directions:
    c
    d
    • 3
    • 21
  • s

    SrSouza

    06/16/2019, 9:52 PM
    Hi @ilya.chernikov, I don't know if here is the right place to ask but, you can tell me if the Kotlin Compiler Plugin has something an intermediate presentation for generate Kotlin code? I'm asking that because I know that if you are making a compiler plugin for JVM target you can use Object ASM to generate bytecode but if in my plugin I want to be multiplatform I will need to write the IR for the LLVM and I have no idea how to do that.
    i
    • 2
    • 1
  • m

    MrPowerGamerBR

    06/17/2019, 3:40 PM
    In Kotlin 1.3.31, how can I use the script engine? It was working fine in 1.3.21, but after I updated to 1.3.31 the engine says
    warning: default scripting plugin is disabled: The provided plugin org.jetbrains.kotlin.scripting.compiler.plugin.ScriptingCompilerConfigurationComponentRegistrar is not compatible with this version of compiler
    and trying to execute anything throws an exception.
    e
    • 2
    • 2
  • g

    gianluz

    07/06/2019, 8:02 PM
    Hi all!! 😄 i'm trying to run a script with dependencies.. here my script:
    script.main.kts
    @file:Repository("<https://repo1.maven.org/maven2>")
    @file:DependsOn("org.apache.commons:commons-text:1.6")
    
    import org.jetbrains.kotlin.script.util.DependsOn
    import org.jetbrains.kotlin.script.util.Repository
    
    import org.apache.commons.text.WordUtils
    
    val hello = "helloWorld"
    print(hello)
    print(WordUtils.capitalize(hello))
    $: kotlinc -cp kotlin-main-kts-1.3.41.jar -script script.main.kts
    script.main.kts:7:12: error: unresolved reference: apache
    import org.apache.commons.text.WordUtils
               ^
    script.main.kts:11:7: error: unresolved reference: WordUtils
    print(WordUtils.capitalize(hello))
          ^
    i do not understand what's wrong here.. 😢
    i
    • 2
    • 3
  • g

    Gary Tierney

    07/16/2019, 3:10 AM
    What's the current script definition story in IDEA? Last I'd used it, searching IDEA build directories of a projects dependencies would make script template discovery work. Does that work when build tasks are delegated to Gradle?
    i
    • 2
    • 1
  • n

    Nikky

    07/25/2019, 7:01 AM
    so does
    kotlinScriptDef
    replace
    META-INF/kotlin/script/templates/...
    ? when using gradle ofc and when i use this, do i change how i set up my folders in idea? currently i mark them as sources root so idea does highlighting
    g
    i
    • 3
    • 2
  • n

    Nikky

    07/25/2019, 9:54 AM
    also will it be possible to run kotlin scripts with arguments from gradle ? that would make some stuff a lot easier
    i
    • 2
    • 1
  • g

    Gary Tierney

    07/25/2019, 9:57 AM
    seems like that'd be better placed for *.gradle.kts to handle
    n
    • 2
    • 3
  • g

    Gerard de Leeuw

    07/25/2019, 12:58 PM
    Anyone else thinks this change is kinda weird? https://github.com/JetBrains/kotlin/commit/67ad3773de2b12f7e1d29e00151b997a4f6373ba#r34443917
    i
    • 2
    • 1
  • j

    jdemeulenaere

    07/31/2019, 3:04 PM
    I would like to evaluate Kotlin code on the JVM and just get the printed output. What's the easiest way to do it ? I tried playing with
    BasicJvmScriptingHost
    but I get a lot of weird errors and lost already so much time on this... In the end I just want a function that takes a String input (kotlin code) and outputs the printed output of the evaluated code, i.e:
    evaluate("""println("Hello World")""") // returns "Hello World"
    i
    • 2
    • 1
  • g

    Gary Tierney

    07/31/2019, 3:18 PM
    you can use the
    ScriptEvaluator
    to get a single return value from a script, but that's a bit different from capturing all printed output
    i
    j
    • 3
    • 7
  • j

    jdemeulenaere

    07/31/2019, 3:33 PM
    https://pastebin.com/5un4j3NE is what I currently have, and prints:
    Executing script...
    [ERROR] Not a script file
    Executed script
    i
    • 2
    • 1
Powered by Linen
Title
j

jdemeulenaere

07/31/2019, 3:33 PM
https://pastebin.com/5un4j3NE is what I currently have, and prints:
Executing script...
[ERROR] Not a script file
Executed script
i

ilya.chernikov

07/31/2019, 4:01 PM
If you setting up an expected filename extension (btw, “script.kt” is not a good extension, you’ll get too many clashes with regular kotlin files), and then create a script from a string, hen you need to specify a correct name (with extension) on
.toScriptSource
call.
View count: 1