Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ Kotlin - How do I fix "Ensure that you have a dependency on the Kotlin standard library" in a project?

I've been trying to set up a new Kotlin project in IntelliJ IDEA, using the default IntelliJ Build System (not Gradle) and JDK 15. Whenever it creates the default main.kt file, and I try to build and run the main function, which looks like this:

fun main(args: Array<String>) {
    println("Hello World!")
}

the build fails after a short time with the following errors:

Kotlin: Cannot access built-in declaration 'kotlin.Array'. Ensure that you have a dependency on the Kotlin standard library

Kotlin: Cannot access built-in declaration 'kotlin.String'. Ensure that you have a dependency on the Kotlin standard library

and

Kotlin: Unresolved reference: println

I've tried changing the project SDK to the kotlin SDK, to Java 14 and to Java 1.8. I'm not sure exactly how to add the dependency it asks for. Any help is appreciated.

This is what the dependencies window shows within the project: Module Dependencies

Right now the project is using JDK 15, and Kotlin 1.4.10. I've tried updating the plugin, uninstalling and reinstalling, deactivating and reactivating, all to no avail.

The project files can be found here on Google Drive

like image 561
A. P. Roblem Avatar asked Nov 19 '20 07:11

A. P. Roblem


2 Answers

Removing the .idea/library file inside the project directory and then selecting "use library from plugin" when prompted to configure Kotlin files by the IDE solved the problem.

like image 200
A. P. Roblem Avatar answered Nov 01 '22 18:11

A. P. Roblem


Please provide more information and check what Kotlin version do you have installed:

  1. Tools > Kotlin > Configure Kotlin Plugin Updates: install the latest version of Kotlin

  2. File > Project Structure > Project: what is your Project SDK there? Choose 15 (something line java version "15.0.1"). If you don't have 15 there, click "+" and add the newest version (unless you need an older version).

like image 36
JetBrains Avatar answered Nov 01 '22 17:11

JetBrains