我创建了一个测试项目,旨在从IntelliJ IDEA CE中的Kotlin开始.

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.

IDEA中Kotlin的正确配置是什么?

谢谢

推荐答案

判断一下你的 idea 是否是up to date.创建新项目时,您可以按如下方式 Select Kotlin:

Project creation with Kotlin

这将自动为您提供configure Kotlin美元.如果您开始了一个Java项目,并且想要Kotlin支持,那么在右下角会有一个小窗口来为您配置项目中的Kotlin.(not needed if the project is created like shown above)

Kotlin configuration in Java project

在这里,你想 Select Java,而不是Javascript,然后点击"Configure '...' module in '...' project 102..."

当你的项目设置正确时,点击make sure that your main function is called "main" and has a parameter of type 100.

fun main(args: Array<String>) {

}

Next to it a Kotlin "K" will appear, which you can click on to run your main function.

Main function execution

Kotlin相关问答推荐

在KMM合成多平台中创建特定于平台的视图

在Mapstruct中重用@映射定义

用vararg替换列表的设计弃用警告

为什么 Kotlin 中没有 init 块的注释

当我通过媒体通知更改音乐时不要更新我的 UI

Kotlin 基于参数类型的返回类型推断

通过顺序多米诺骨牌操作列表管理对象的最佳方法是什么?

parallelStream()和asSequence().asStream().parallel()之间的区别

Kotlin 日期格式从一种更改为另一种

如何在 IntelliJ 中更改 Kotlin 的this property has a backing field代码编辑器突出显示?

如何在主线程上使用 Kotlin 协程 await()

以编程方式重新启动 Spring Boot 应用程序/刷新 Spring 上下文

更新到版本4.10.1/4.10.2后 Gradle 同步失败

将ExpectedException与Kotlin一起使用

是否在Kotlin中重写enum toString()?

在 Kotlin 函数上使用 Mokito anyObject() 时,指定为非 null 的参数为 null

Dagger +Kotlin 不注入

在 sharedPref.getString 中有一个默认值有什么意义?

Kotlin中的函数接口

Kotlin - 如何获取注释属性值