I am trying to get Kotlin to work inside VSCode. So far with kotlin extensions I've managed to get it working partially. I can use any Kotlin specific class or function, but I can't import any java specific class. (error: unresolved reference)
When I've compared the VSCode project to an Eclipse one and an IDEA one I've noticed that both have the JRE in the project folder (in IDEA case as an External Library). Pretty sure that is my problem in VSCode, but I don't know how to add the JRE to my project.
I am using Gradle for my project:
buildscript {
ext.kotlin_version = '1.2.71'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
kotlin {
experimental {
coroutines 'enable'
}
}
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:0.21"
}
As you can see I have the Kotlin-JVM plugin, but apart from that I am not aware of a way of adding the JRE to gradle. Can anyone please help me out?
Edit: I've tried adding kotlin coroutines to the project only to find out that even this external library won't work (I am getting the unresolved reference error both on the import kotlinx.coroutines.experimental.* and on the async function). This makes me believe that gradle isn't aware of the actual project and won't import any required dependencies.
When created the project I've used the gradle init command, modified the build.gradle file and then created a main.kt file at the root of the project (no actual code in the file, just the main function, the import statement and a call to async)
JAVA_HOMEvariable globally and gradle should be able to find it. If you are running Linux, this should be done by your distro when installing Java, but otherwise/etc/profileis a good place to define the variable. Otherwise, I recommend changing the OS on the long run and use Google to find a temporary solutiongradle initworks this means gradle can find the JRE (gradle cannot launch without it). Trygradle assembleto see whether your problem is with gradle or with VSCodeasyncas an error, but after a restart that syntax error is gone and I even get the documentation reference, so is not from VSCode. I am thinking I am running the code with the wrong command or I need some specific folder structure. If you've used Atom,what command did you use to build the project?