简体   繁体   English

如何在 Intellij IDEA 中使用 Gradle 创建 Kotlin 控制台应用程序

[英]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我从 JetBrains 找到了这个教程: https ://www.jetbrains.com/help/idea/create-your-first-kotlin-app.html ? section = Gradle%20Kotlin

It is dated August 19th, 2020.日期为 2020 年 8 月 19 日。

I am using the same IntelliJ IDEA version as in their documentation: 2020.2.我使用的是与他们的文档中相同的 IntelliJ IDEA 版本: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.我看不到在哪里可以选择控制台应用程序模板或 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:我找到了第二个教程 - https://kotlinlang.org/docs/tutorials/jvm-get-started.html ,它显示了 New Project 向导的第三个变体:

在此处输入图片说明

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?如何使用 Gradle 基于控制台应用程序模板创建 Kotlin 项目?

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 ).最近有一个全新的,作为 Kotlin 1.4 的一部分发布(见这里)。
Most probably, the problem is caused by the Kotlin IDE plugin being outdated or something.最有可能的是,问题是由 Kotlin IDE 插件过时或其他原因引起的。 Please try to delete in and re-install using the Preferences -> Plugins menu.请尝试使用Preferences -> Plugins菜单删除并重新安装。 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.因此,使用“JVM/IDEA”选项创建一个新项目。 If it already opens up a main.kt file, you don't need to do anything else.如果它已经打开了一个main.kt文件,你不需要做任何其他事情。 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).如果没有,请查看src文件夹 - 您应该看到一个名为main的文件夹, kotlin有一个名为kotlin的文件夹(带有一个蓝色图标而不是灰色) - 这里是您要创建主文件的位置(右键单击 -> new kotlin file/class -> main.kt并将其main.kt文件,而不是类)。 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 ).注意:如果您没有kotlin文件夹,请在带有蓝色图标的文件夹中创建文件(甚至可能是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.此外,如果这不使用 Gradle(出于某种原因),请创建一个 Gradle 项目,然后在“其他库和框架”选项中,取消选中 Java 并选中 Kotlin,如果不是,则继续创建main.kt创建。

You may create a Kotlin + gradle project from the terminal:你可以从终端创建一个 Kotlin + gradle 项目:

$mkdir myProject; cd myProject; gradle init

follow the tutorial.按照教程。

And then start the Intellij & open the dir You're good to go然后启动 Intellij 并打开目录你很高兴去

Same process like this 同样的过程是这样的

The same happened to me but I figured out how to fix it:同样的事情发生在我身上,但我想出了如何解决它:

Just disable Material Theme UI.只需禁用 Material Theme UI。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Kotlin 使用 gradle Intellij 构建未使用新控制台应用程序项目构建 - Kotlin build not building with fresh console application project using gradle Intellij 如何为 IntelliJ IDEA Gradle 插件设置 Kotlin PSI? - How to set up Kotlin PSI for IntelliJ IDEA Gradle Plugin? IntelliJ IDEA 存在 Kotlin Gradle 依赖问题 - IntelliJ IDEA having problem with Kotlin Gradle dependency 如何以编程方式为Intellij Idea创建自定义Kotlin Inspection - How to create a custom Kotlin Inspection for Intellij Idea programmatically 开发IntelliJ Idea插件时如何创建kotlin类? - how to create kotlin class when developing intellij idea plugin? 如何在用 Kotlin 编写的 Intellij IDEA Gradle 插件项目中包含 Kotlin PSI 类(例如 KtClass)? - How to include Kotlin PSI classes (e.g. KtClass) in Intellij IDEA Gradle plugin project written in Kotlin? Protobuf配置Intellij Idea插件Gradle-kotlin-dsl kotlin - Protobuf configuration Intellij Idea Plugin Gradle-kotlin-dsl kotlin 在 IntelliJ Idea 中开发 Visual Kotlin 应用程序 - Developing a Visual Kotlin Application in IntelliJ Idea Intellij Idea插件,创建Kotlin PSI访问者 - Intellij Idea Plugin, Create Kotlin PSI Visitor 尝试更新到 Kotlin 1.4.0 时出现奇怪的错误。 如何使其与 Gradle 和 IntelliJ IDEA 2020.2.1 一起使用? - Getting weird bugs when trying to update to Kotlin 1.4.0. How to make it work with Gradle and IntelliJ IDEA 2020.2.1?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM