Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Kotlin function in Intellij Idea

I have created a test project aiming to start with Kotlin in IntelliJ IDEA CE.

The IDE version and the system is 2017.1.4 Build #IC-171.4694.23, built on June 6, 2017 JRE: 1.8.0_112-release-736-b21 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Mac OS X 10.12.4

There is one .kt file with a main function in it. When I right-click on it I can select Run, but I get an error form JUnit: !!! JUnit version 3.8 or later expected.

I figured out it was about missing configuration, but I can't set up a proper one for Kotlin as well. Namely it requires a 'main class', which I don't have. Setting package name instead, as some other discussions suggest didn't help either.

What is the proper configuration for Kotlin in IDEA?

Thanks!

like image 962
Bord81 Avatar asked Jun 18 '17 12:06

Bord81


People also ask

How do I run Kotlin main function in IntelliJ?

When your project is set up correctly, make sure that your main function is called "main" and has a parameter of type Array<String> . Next to it a Kotlin "K" will appear, which you can click on to run your main function.

Can you use Kotlin in IntelliJ?

IntelliJ IDEA provides first-class support for Kotlin. It includes Kotlin-specific project templates, coding assistance, refactorings, debugging, analysis tools, and so on.


1 Answers

Coming from a Java background, I instinctively put the main function inside a class. Then IntelliJ wouldn't let me run it. After taking the main function out of class to the top level, IntelliJ automatically put the green arrow next to the main function and added Run to the context menu (brought up by right clicking the file).

like image 177
Big Pumpkin Avatar answered Sep 23 '22 18:09

Big Pumpkin