```$ ./jvm/main-kts/scripts/kotlin-shell.main.kts ...
# scripting
f
Copy code
$ ./jvm/main-kts/scripts/kotlin-shell.main.kts 
:: problems summary ::
:::: WARNINGS
		module not found: eu.jrie.jetbrains#kotlin-shell-core;0.2.1

	==== central: tried

	  <https://repo1.maven.org/maven2/eu/jrie/jetbrains/kotlin-shell-core/0.2.1/kotlin-shell-core-0.2.1.pom>

	  -- artifact eu.jrie.jetbrains#kotlin-shell-core;0.2.1!kotlin-shell-core.jar:

	  <https://repo1.maven.org/maven2/eu/jrie/jetbrains/kotlin-shell-core/0.2.1/kotlin-shell-core-0.2.1.jar>

error: cannot access script base class 'org.jetbrains.kotlin.mainKts.MainKtsScript'. Check your module classpath for missing or conflicting dependencies (kotlin-shell.main.kts:3:1)
error: unresolved reference: Repository (kotlin-shell.main.kts:3:7)
error: unresolved reference: DependsOn (kotlin-shell.main.kts:4:7)
error: unresolved reference: DependsOn (kotlin-shell.main.kts:5:7)
error: unresolved reference: CompilerOptions (kotlin-shell.main.kts:6:7)
error: unresolved reference: kotlinx (kotlin-shell.main.kts:7:13)
error: an annotation argument must be a compile-time constant (kotlin-shell.main.kts:7:13)
error: unresolved reference: eu (kotlin-shell.main.kts:9:8)
error: unresolved reference: shell (kotlin-shell.main.kts:11:1)
error: unresolved reference: args (kotlin-shell.main.kts:12:9)
error: expression '"ls -l"' of type 'String' cannot be invoked as a function. The function 'invoke()' is not found (kotlin-shell.main.kts:13:9)
error: unresolved reference: pipeline (kotlin-shell.main.kts:21:9)
error: unresolved reference: args (kotlin-shell.main.kts:22:20)
error: unresolved reference: process (kotlin-shell.main.kts:22:30)
error: unresolved reference: streamLambda (kotlin-shell.main.kts:23:21)
error: cannot infer a type for this parameter. Please specify it explicitly. (kotlin-shell.main.kts:23:36)
error: cannot infer a type for this parameter. Please specify it explicitly. (kotlin-shell.main.kts:23:42)
error: cannot infer a type for this parameter. Please specify it explicitly. (kotlin-shell.main.kts:23:45)
error: expression '"wc ${args[0]}"' of type 'String' cannot be invoked as a function. The function 'invoke()' is not found (kotlin-shell.main.kts:44:9)
error: unresolved reference: args (kotlin-shell.main.kts:44:15)
jvm/main-kts/scripts/kotlin-shell.main.kts: error: unresolved dependency: eu.jrie.jetbrains#kotlin-shell-core;0.2.1: not found
jvm/main-kts/scripts/kotlin-shell.main.kts:3:1: error: cannot access script base class 'org.jetbrains.kotlin.mainKts.MainKtsScript'. Check your module classpath for missing or conflicting dependencies
@file:Repository("<https://dl.bintray.com/jakubriegel/kotlin-shell>")
^
jvm/main-kts/scripts/kotlin-shell.main.kts:3:7: error: unresolved reference: Repository
@file:Repository("<https://dl.bintray.com/jakubriegel/kotlin-shell>")
      ^
jvm/main-kts/scripts/kotlin-shell.main.kts:4:7: error: unresolved reference: DependsOn
@file:DependsOn("eu.jrie.jetbrains:kotlin-shell-core:0.2.1")
      ^
jvm/main-kts/scripts/kotlin-shell.main.kts:5:7: error: unresolved reference: DependsOn
@file:DependsOn("org.slf4j:slf4j-simple:1.7.28")
      ^
jvm/main-kts/scripts/kotlin-shell.main.kts:6:7: error: unresolved reference: CompilerOptions
@file:CompilerOptions("-Xopt-in=kotlin.RequiresOptIn")
      ^
jvm/main-kts/scripts/kotlin-shell.main.kts:7:13: error: unresolved reference: kotlinx
@file:OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
            ^
jvm/main-kts/scripts/kotlin-shell.main.kts:7:13: error: an annotation argument must be a compile-time constant
@file:OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
            ^
jvm/main-kts/scripts/kotlin-shell.main.kts:9:8: error: unresolved reference: eu
import eu.jrie.jetbrains.kotlinshell.shell.*
       ^
jvm/main-kts/scripts/kotlin-shell.main.kts:11:1: error: unresolved reference: shell
shell {
^
jvm/main-kts/scripts/kotlin-shell.main.kts:12:9: error: unresolved reference: args
    if (args.isEmpty()) {
        ^
jvm/main-kts/scripts/kotlin-shell.main.kts:13:9: error: expression '"ls -l"' of type 'String' cannot be invoked as a function. The function 'invoke()' is not found
        "ls -l"()
        ^
jvm/main-kts/scripts/kotlin-shell.main.kts:21:9: error: unresolved reference: pipeline
        pipeline {
        ^
jvm/main-kts/scripts/kotlin-shell.main.kts:22:20: error: unresolved reference: args
            "cat ${args[0]}".process() pipe
                   ^
jvm/main-kts/scripts/kotlin-shell.main.kts:22:30: error: unresolved reference: process
            "cat ${args[0]}".process() pipe
                             ^
jvm/main-kts/scripts/kotlin-shell.main.kts:23:21: error: unresolved reference: streamLambda
                    streamLambda { strm, _, _ ->
                    ^
jvm/main-kts/scripts/kotlin-shell.main.kts:23:36: error: cannot infer a type for this parameter. Please specify it explicitly.
                    streamLambda { strm, _, _ ->
                                   ^
jvm/main-kts/scripts/kotlin-shell.main.kts:23:42: error: cannot infer a type for this parameter. Please specify it explicitly.
                    streamLambda { strm, _, _ ->
                                         ^
jvm/main-kts/scripts/kotlin-shell.main.kts:23:45: error: cannot infer a type for this parameter. Please specify it explicitly.
                    streamLambda { strm, _, _ ->
                                            ^
jvm/main-kts/scripts/kotlin-shell.main.kts:44:9: error: expression '"wc ${args[0]}"' of type 'String' cannot be invoked as a function. The function 'invoke()' is not found
        "wc ${args[0]}"()
        ^
jvm/main-kts/scripts/kotlin-shell.main.kts:44:15: error: unresolved reference: args
        "wc ${args[0]}"()
              ^
Anyone? 😢
m
Double checking: do you have Kotlin 1.3.70 in your path ?
What does
env kotlin
say?
f
Yes!
Copy code
$ env kotlin
Welcome to Kotlin version 1.3.70 (JRE 1.8.0_232-b09)
Type :help for help, :quit for quit
>>>
i
Sorry for the long delay. The root problem is this:
Copy code
error: cannot access script base class 'org.jetbrains.kotlin.mainKts.MainKtsScript'
That means that you have an atypical installation, and kotlin compiler is not able to find
kotlin-main-kts.jar
, and interprets all scripts as a default ones. How is the kotlin compiler installed in your system? And can you have a look at the folder where
kotlin-compiler.jar
is located?
f
I installed with Homebrew
j
Any solution?
I tried out the sample scripts at https://github.com/Kotlin/kotlin-script-examples/blob/master/jvm/main-kts/MainKts.md and encountered similar error. The problem is not homebrew version. I tried remove homebrew kotlin and manually install the release from Github, and it did not work. Then I open up IntelliJ IDEA, and create the script file inside the IDE. And when I go back to run the script inside terminal, it works! So somehow the IDE is able to pull down the dependencies correctly, which the command line “kotlin” is having problem.
i
thanks for the investigation, @Jaxon Du! I'll try to find out what's the root of the problem.
j
@ilya.chernikov I also noticed setting the env variable
KOTLIN_MAIN_KTS_COMPILED_SCRIPTS_CACHE_DIR does not work. I'm on latest macOS.