简体   繁体   中英

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:

在此处输入图片说明

But for me, it looks like this:

在此处输入图片说明

and when I click on Next: 在此处输入图片说明

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:

在此处输入图片说明

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?

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.

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.

You may create a Kotlin + gradle project from the terminal:

$mkdir myProject; cd myProject; gradle init

follow the tutorial.

And then start the Intellij & open the dir You're good to go

Same process like this

The same happened to me but I figured out how to fix it:

Just disable Material Theme UI.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM