https://kotlinlang.org logo
m

mbonnin

04/03/2020, 5:03 PM
Do
*.main.kts
support dependencies resolution ? The following doesn't work:
Copy code
#!/usr/bin/env kotlin

@file:DependsOn("com.squareup.moshi:moshi:1.9.2")
@file:DependsOn("com.squareup.okio:okio:2.4.3")

import okio.source // error: unresolved reference: source
import <http://java.io|java.io>.File

File("foo").source()
if I swap the imports of okio and moshi, it works well though, leading me to think that the script will import the first version it encounters ?
j

jimn

04/03/2020, 7:52 PM
im just coming in from the cold.. where is
@file:DependsOn
documented? i didn't see this as i was perusing the kotlinc and REPL page
my workaround for hte sum of a few hours experimentation is
Copy code
export JAVA_OPTS=-Xmx512m ; kotlinc-jvm  -Xnew-inference -jvm-target 11  -cp $(find  ../cursor/target/ -name '*jar'|xargs -n999 echo|tr ' ' :) -script histogram.kts  `
m

mbonnin

04/03/2020, 9:01 PM
It's the
kotlin-main-kts
artifact (https://github.com/Kotlin/KEEP/blob/master/proposals/scripting-support.md#kotlin-main-kts). Things got pretty improved in kotlin 1.3.70 so now you can just name a file *.main.kts and it will pull
kotlin-main-kts
in the classpath: (changelog: https://blog.jetbrains.com/kotlin/2020/03/kotlin-1-3-70-released/)
Another option is to use kscript, which also supports
DependsOn
j

jimn

04/04/2020, 3:25 AM
does @file:DependsOn("com.squareup.okiookio2.4.3") bring in transitive deps?
m

mbonnin

04/13/2020, 12:23 AM
@jimn sorry for the super long delay. I think it brings transitive deps but dependencies resolution doesn't seem great at the momentt. As in, it'll take the first version encountered