Did I miss some settings or it’s a small bug of IDEA?
Also, the debug icon is de-activated. Will it be enabled in the future?
Thanks.
This is the version I used:
IntelliJ IDEA 2017.3.3 (Ultimate Edition)
Build #IU-173.4301.25, built on January 16, 2018
JRE: 1.8.0_152-release-1024-b11 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.13.2
I’m able to run (though not debug) *.kts files through IntelliJ.
I installed the Kotlin compiler via homebrew. I also had to specify a JDK in the project configuration as one was not configured by default. Here’s the version info:
IntelliJ IDEA 2017.3.4 (Ultimate Edition)
Build #IU-173.4548.28, built on January 29, 2018
JRE: 1.8.0_152-release-1024-b11 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.13.3
Also, the sample code snippet takes a directory as an argument, so you’ll want to provide that as program argument in the run configuration.
IntelliJ IDEA 2017.3.4 (Ultimate Edition)
Build #IU-173.4548.28, built on January 29, 2018
JRE: 1.8.0_152-release-1024-b11 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.13.0-32-generic
The script does run fine, the problem is that IDEA does not validate the code correctly and falsely reports 4 errors in 3 lines of code:
Is this a configuration problem? Do we miss some settings?
Also, in scripting I want to pass exit codes to the calling shell to indicate success or failure of the script run. I tried to do that with exitProcess (exitProcess - Kotlin Programming Language), but that reults in error: unresolved reference: exitProcess. What is the recommended way to return an exit code from a kotlin script?
Thanks, @reitzig! Your reply solved both of my problems:
As of this morning I cannot reproduce any more the IDE problem. The errors in IDEA have disappeared magically (on my Linux installation as well as on Windows. )
yes, System.exit(n) works, as well as exitProcess(n), where now IDEA kindly offers to add
Error:(3, 1) Kotlin: Cannot access script base class ‘kotlin.script.templates.standard.ScriptTemplateWithArgs’. Check your module classpath for missing or conflicting dependencies
Running the script from the command line is fine.
Also tried restarting IntelliJ (with invalidate caches)
I was able to fix kts problems in Intellij 2017.3 by moving my kts files into the main directory. That is into a directory that belongs to some module. When they were outside of modules (in root directory), the syntax errors were appearing.