简体   繁体   English

intelliJ Idea 中的 Kotlin 包结构

[英]Kotlin package structure in intelliJ Idea

I'm trying to setup kotlin unit test with gradle build system in IntelliJ IDE by following this tutorial .我正在尝试按照本教程在 IntelliJ IDE 中使用 gradle 构建系统设置 kotlin 单元测试。 I have created an project named test.sample which contains only src folder by default.我创建了一个名为test.sample的项目,默认情况下它只包含 src 文件夹。

在此处输入图片说明

Then in the intelliJ terminal I created a gradle project manually.然后在 intelliJ 终端中我手动创建了一个 gradle 项目。

在此处输入图片说明

Now my problem is after creating the gradle project it creates main and test folder inside src file, but i'm getting import package error as you can see in the below image.现在我的问题是在创建 gradle 项目后,它在 src 文件中创建了 main 和 test 文件夹,但是我收到了导入包错误,如下图所示。

在此处输入图片说明

The error disappears if i change the import path to main.kotlin.test.sample but i want the import should be test.sample.如果我将导入路径更改为main.kotlin.test.sample ,错误就会消失,但我希望导入应该是 test.sample。 How do i exclude main.kotlin from package directory.我如何从包目录中排除 main.kotlin。

If you are using Gradle or Maven, follow the standard directories layout for these build systems.如果您使用 Gradle 或 Maven,请遵循这些构建系统的标准目录布局。

If you import the project in IntelliJ IDEA from build.gradle , it will set the source root to src/main/kotlin instead of src and your imports will work properly.如果您在 IntelliJ IDEA 中从build.gradle导入项目,它会将源根设置为src/main/kotlin而不是src ,您的导入将正常工作。

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

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