2

I am trying to run .kts scripts (using Script Engine) from a Kotlin program.

The Kotlin scripts reside in the resource folder of the project and normally they have support for auto-completion, IDE checks, auto-complete, etc.

The problem appeared when I wanted to pass external variables to the script using bindings. I am doing something like:

scriptEngine.eval(scriptContent, scriptEngine.createBindings().apply { putAll(bindings) })

The bindings is a Map<String, Any> that contains the variables I want to access in my script: bindings["variable"].

Problem is that IntellIJ doesn't recognize bindings in the .kts script, so it shows a "unresolved reference: bindings". If I run the script from command line everything is fine, but inside IntelliJ i have this problem.

Is there a way to overcome the issue ? Has any experienced the same problem?

Andrei Ciobanu
  • 12,500
  • 24
  • 85
  • 118

0 Answers0