How can I import other classes in Kotlin Script? (Classes in normal .kt files or .java files or even .class files)

Hello,

I just get to know that Kotlin can be used as a scripting language as well, which is great, but I am having so much trouble with it: not enough documentation and tutorials and maybe even IDE support.

The problem I facing is how I cannot import other classes inside Kotlin script (auto complete works file but error at runtime). For example, in a normal project, i want to create a script and interact with other normal Kotlin and Java classes, how should I do it? I tried the normal way of importing but received error “unresolved references” (I even added the path to maven target/classes folder, but no luck)

My question is: Is it possible to import from/to Kotlin scripts? If yes, how can we do it?

Thank you.

1 Like

Currently Kotlin scripting doesn’t have a proper facility for importing, however if KScript is used instead then full importing is available.

1 Like