简体   繁体   English

IntelliJ IDEA:无法导入 SBT 项目

[英]IntelliJ IDEA: Cannot import SBT project

I'm completely new to development using Play or IntelliJ for that matter.就此而言,我对使用 Play 或 IntelliJ 进行开发是完全陌生的。 I've created a simple HelloWorld application using Activator, and this is an sbt project.我使用 Activator 创建了一个简单的 HelloWorld 应用程序,这是一个sbt项目。

I've been trying to import this to IntelliJ and this is the screen I'm stuck at: https://www.dropbox.com/s/we1a4a3184sojvb/Screenshot%202014-07-24%2016.57.11.png我一直在尝试将其导入 IntelliJ,这是我卡在的屏幕: https://www.dropbox.com/s/we1a4a3184sojvb/Screenshot%202014-07-24%2016.57.11.png

In almost all tutorials I've been through online, I've seen people using an sbt option on the import screen.在我浏览过的几乎所有在线教程中,我都看到有人在导入屏幕上使用sbt选项。 I've installed the SBT plugin as well, but that hasn't helped.我也安装了 SBT 插件,但这并没有帮助。 I've restarted IntelliJ several times to no avail.我已经多次重新启动 IntelliJ 无济于事。

Where am I going wrong?我哪里错了? I'm running 13.1.4 with the SBT plugin installed.我正在运行SBT 13.1.4

I had this error when importing a new module from existing sources.从现有源导入新模块时出现此错误。

  • On the right-hand side of your IntelliJ window, you will see a list of vertical tabs, open the SBT tab.在 IntelliJ 窗口的右侧,您将看到一个垂直选项卡列表,打开SBT选项卡。
  • Select the module that's causing trouble, right click on it, select "Detach external project"选择引起问题的模块,右键单击它,选择“分离外部项目”
  • Try to import the module again.再次尝试导入模块。
  1. Move to /your-project-folder移至/your-project-folder
  2. Run ./activator运行./activator
  3. Type idea .输入idea It will generate IDEA project.它将生成 IDEA 项目。
  4. Open (not import) File->Open.. project in IDEA.在 IDEA 中打开(不是导入) File->Open..项目。

I had a similar problem which came from a different place than the other solutions here so adding it in case it occurs for others.我有一个类似的问题,它来自与这里的其他解决方案不同的地方,所以添加它以防其他人发生。

In my case the problem was caused by accidentally opening the IdeaProjects directory.在我的情况下,问题是由意外打开 IdeaProjects 目录引起的。 When you do this, it creates the .Idea folder in that directory, and populates it as a project.执行此操作时,它会在该目录中创建 .Idea 文件夹,并将其作为项目填充。 This apparently also confuses the set import.这显然也混淆了集合导入。

The solution is to remove the .Idea folder and open (not import) the directory again.解决方案是删除 .Idea 文件夹并再次打开(而不是导入)目录。

I encountered the same error when I was trying to import a new scala project A to an existing IntelliJ project B as a module.当我尝试将新的 Scala 项目 A 作为模块导入到现有的 IntelliJ 项目 B 时遇到了同样的错误。 I solved the problem by following step below:我通过以下步骤解决了这个问题:

  1. Go to your folder of project B. Open file .idea/sbt.xml.转到项目 B 的文件夹。打开文件 .idea/sbt.xml。
  2. Deleting the entry which includes the path of project A.删除包含项目 A 路径的条目。

After a series of struggles, I must say something weird solved this problem – moving to IntelliJ IDEA Ultimate.经过一系列的挣扎,我必须说一些奇怪的东西解决了这个问题——转向 IntelliJ IDEA Ultimate。 That has built in Play application support and can run/debug/test the application out of the box, which is very handy.它内置了 Play 应用程序支持,可以开箱即用地运行/调试/测试应用程序,非常方便。

All I can say after this experience was that JetBrains wants you to upgrade to Ultimate if you want things to work right out of the box.在这次经历之后,我只能说 JetBrains 希望你升级到 Ultimate,如果你想让事情开箱即用。

I'm sure there are ways to get this working with CE also, but I wasn't successful with that.我相信也有办法让 CE 与它一起工作,但我没有成功。

  1. Uninstall everything卸载一切
  2. Reinstall IntelliJ重新安装 IntelliJ
  3. Install the JetBrains official Scala plugin安装JetBrains 官方 Scala 插件
  4. Import the project导入项目

    • Make sure that the project has a build.sbt file in the right place, so that IntelliJ can find it as an SBT project.确保项目在正确的位置有一个build.sbt文件,以便 IntelliJ 可以找到它作为 SBT 项目。
    • This is about IntelliJ IDEA version 13.1.4.这是关于 IntelliJ IDEA 版本 13.1.4。

此问题已在 SBT 和 Scala 插件的最新更新中解决。

Make sure that your java path is correct ( IntelliJ can use other path than system defined )确保您的 java 路径正确( IntelliJ 可以使用系统定义之外的其他路径

Preferences -> Build, Execution, Deployment -> sbt -> JVM - choose a correct JRE Preferences -> Build, Execution, Deployment -> sbt -> JVM - 选择一个正确的 JRE

Solved for解决了

IntelliJ IDEA 2022.2.1 (Ultimate Edition)
scala plugin: 2022.2.12
sbt version: 1.7.1

doing these steps:执行以下步骤:

  1. Unlink sbt Project(sbt toolbar), then link it again.取消链接 sbt 项目(sbt 工具栏),然后再次链接。
  2. Delete modules ( ctrl + alt + shift + s ).删除模块( ctrl + alt + shift + s )。
  3. Remove .bsp/, and.idea/ config files.删除.bsp/ 和 .idea/ 配置文件。
  4. Invalidate caches..( ctrl + f ).使缓存无效..( ctrl + f )。
  5. Restart IDEA.重启IDEA。

The number of steps to make it work may vary.使其工作的步骤数量可能会有所不同。

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

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