Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a Kotlin console application with Gradle in Intellij IDEA

I found this tutorial from JetBrains: https://www.jetbrains.com/help/idea/create-your-first-kotlin-app.html?section=Gradle%20Kotlin

It is dated August 19th, 2020.

I am using the same IntelliJ IDEA version as in their documentation: 2020.2.

However, my project creation wizard looks quite different from theirs.

They provide this screenshot:

enter image description here

But for me, it looks like this:

enter image description here

and when I click on Next: enter image description here

I don't see where I can choose the Console Application template, or Gradle.

I found a second tutorial - https://kotlinlang.org/docs/tutorials/jvm-get-started.html , which shows yet a third variation of the New Project wizard:

enter image description here

Are the tutorials out of date? Am I doing anything wrong? How do I create a Kotlin project, based on a console application template, with Gradle?

like image 991
obe Avatar asked Dec 30 '22 20:12

obe


2 Answers

The wizard you have seems to be obsolete now. There was a brand-new one, released as a part of Kotlin 1.4 recently(see here).
Most probably, the problem is caused by the Kotlin IDE plugin being outdated or something. Please try to delete in and re-install using the Preferences -> Plugins menu. Comment here with the results, please. I'd like to know if this would help.

like image 128
Artyom Degtyarev Avatar answered Jan 04 '23 16:01

Artyom Degtyarev


Indeed it's quite weird, I've never seen the dialog to look like yours (mine looks like the one in the tutorials). However, choosing the template doesn't do anything special - it simply creates the main file, which you can do so yourself.

So create a new project with the "JVM/IDEA" option. If it already opens up a main.kt file, you don't need to do anything else. If it didn't, look in the src folder - you should see a folder named main with a folder named kotlin (with a blue icon instead of grey) inside - here's where you wanna create your main file (right click -> new kotlin file/class -> main.kt and make it a file, not a class). Finally, put this in the file:

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

Note: if you don't have a kotlin folder, create the file in the folder with the blue icon (might even be src). Also, if this doesn't use Gradle (for some reason), create a Gradle project instead, and at the "Additional libraries and frameworks" option, uncheck Java and check Kotlin, then continue with creating main.kt if it isn't created.

like image 41
Chaoz Avatar answered Jan 04 '23 16:01

Chaoz