如何正确配置IntelliJ IDEA的一个科特林项目?

You may have to configure your Kotlin project in IntelliJ IDEA, 例如,对于您已经从GitHub进口项目. 如果没有正确配置该项目将不会编译/运行,或者你可能会得到错误信息,如“AppKt模块未发现’ 或者你的主要方法不能发现.

The following steps will configure your GitHub Kotlin project

  1. Configure Kotlin in your project
    1. Tools -> Kotlin -> Configure Kotlin in Project
      如何配置这是从现有的GitHub的项目创建一个项目科特林
    2. If you have more than one module choose all modules otherwise Single module will be fine and choose Use library from plugin
    3. Press OK
       如何配置这是从现有的GitHub的项目创建一个项目科特林
  2. Configure the project settings
    1. Create a directory for the Project compiler output
      1. Right click the project root in the Project Tool Window
        1. Choose New -> Directory
        2. Enter new directory name: out
        3. Press OK
        4. Right click the new out directory in the Project Tool Window and choose Copy Path
          如何配置这是从现有的GitHub的项目创建一个项目科特林
    2. Choose File -> Project Structure
      1. In Project compiler output paste in the out directory Path which was copied in the previous step
      2. Select the JDK 1.8 in Project SDK
      3. Select SDK default in Project language level
        注意: if you get any Github prompts click cancel
        如何配置这是从现有的GitHub的项目创建一个项目科特林
    3. Select Modules
      1. Right click src directory and set as Sources
      2. 点击确定
        注意: Cancel or choose No for any Github prompts
        如何配置这是从现有的GitHub的项目创建一个项目科特林
  3. Configure Run and Debug for Kotlin
    1. Open the App.kt file or the file which contains the main application entry point method
      注意: Choose No for any Github prompts
    2. Click the small Kotlin icon to the left of the method
      1. Choose Run ‘AppKt
        如何配置这是从现有的GitHub的项目创建一个项目科特林

Your project configuration is now complete and your Kotlin app should compile and run with no problems.