简体   繁体   English

IntelliJ 无法导入 sbt 项目

[英]IntelliJ Cannot Import sbt Project

I have upgraded IntelliJ to version CE 2017.3 from a CE 2017.2.5, and now I cannot build my sbt project.我已经将 IntelliJ 从 CE 2017.2.5 升级到 CE 2017.3 版,现在我无法构建我的 sbt 项目。 The build gets stuck on the first step:构建卡在第一步:

"Build: sync
  MyProjName: syncing...
   dump project structure from sbt"

I have deleted the .idea directory and the the MyProjName/project/target directory.我已经删除了 .idea 目录和MyProjName/project/target目录。 I did an sbt build from the command line, which worked.我从命令行做了一个 sbt 构建,它有效。 Then I started IntelliJ again and tried to import MyProjName/build.sbt as a project.然后我再次启动 IntelliJ 并尝试将MyProjName/build.sbt作为项目导入。 I have also logged out/in.我也已注销/登录。 Did this several times.这样做了几次。 The import never progresses past this step.导入永远不会超过这一步。

I work behind a firewall, but I have checked my proxy settings, and they are correct and unchanged from the previous version (if this matters).我在防火墙后面工作,但我检查了我的代理设置,它们与以前的版本是正确的并且没有变化(如果这很重要)。

How can I troubleshoot / fix this?我该如何解决/解决这个问题?

The sbt version is 0.13.6. sbt 版本是 0.13.6。 Scala plugin 2017.3.10. Scala 插件 2017.3.10。

From the log:从日志:

IDE: IntelliJ IDEA (build #IC-173.3727.127, 27 Nov 2017 09:32)
OS: Windows 7 (6.1, amd64) 
JRE: 1.8.0_152-release-1024-b6 (JetBrains s.r.o) 
JVM: 25.152-b6 (OpenJDK 64-Bit Server VM) 

I solved the sync issue following info here: https://youtrack.jetbrains.com/issue/SCL-13024我解决了以下信息的同步问题: https : //youtrack.jetbrains.com/issue/SCL-13024

Key info is "It seems that sbt is trying to re-resolve 'sources' and 'docs' for sbt plugins that are not available at all. If properties to download "Library sources" and "sbt sources" are disabled, then time to dump the structure is reduced from 'forever' to less than 1 minute."关键信息是“似乎 sbt 正在尝试重新解析根本不可用的 sbt 插件的‘源代码’和‘文档’。如果下载“库源”和“sbt 源”的属性被禁用,那么是时候转储结构从‘永远’减少到不到 1 分钟。”

That is , in IntelliJ IDEA, clear the check box "Library sources" under "Project level settings" for Build Tools sbt in IDEA preferences.即,在 IntelliJ IDEA 中,清除 IDEA 首选项中 Build Tools sbt 的“项目级别设置”下的“库源”复选框。 As shown in image below:如下图所示:

在此处输入图片说明

我可以解决这个问题的唯一方法是sbt clean compile在 SBT 控制台/cmd 行中运行sbt clean compile ,然后在 IntelliJ 中刷新 SBT 项目。

  • Open a terminal inside IDEA by pressing Alt F12 or use sbt shell通过按Alt F12或使用sbt shell在 IDEA 中打开一个终端
  • Run sbt - if it is first time it will take some time.运行sbt - 如果是第一次,则需要一些时间。
  • Run clean运行clean
  • Run compile - it will download dependencies you have in your project.运行compile - 它将下载您项目中的依赖项。
  • Close IDEA project ( File -> Close Project ) and open it again.关闭 IDEA 项目( File -> Close Project )并再次打开它。

Note: if it asks to import in the right-bottom of the screen activate Enable auto-import , if you don't like to keep it enabled (like me) press Import , cancel the syncronyzation and then Refresh sbt project again.注意:如果它要求在屏幕右下角Enable auto-import ,请激活Enable auto-import ,如果您不喜欢保持启用状态(像我一样)按Import ,取消同步,然后再次Refresh sbt project When you try to use import in the middle of a sync it gets stuck with dump project structure from sbt message.当您尝试在同步过程中使用 import 时,它会被sbt消息中的转储项目结构卡住。

The Refresh sbt project is located at this corner of the Build Sync window - highlighted below: Refresh sbt project位于 Build Sync 窗口的这个角落 - 在下面突出显示: 刷新 sbt 项目

我还没有找到在 IntelliJ Idea CE 2017.3 中完成这项工作的方法,所以我已经恢复到 CE 2017.2.5

IntelliJ appears to limit the efficiency of the already slow sbt update . IntelliJ 似乎限制了已经很慢的sbt update的效率。 I recommend using sbt-coursier instead.我建议改用sbt-coursier It was written specifically to improve dependency update time, and on one large project I'm involved in it improved dependency update time by about 2 orders of magnitude.它是专门为改进依赖项更新时间而编写的,在我参与的一个大型项目中,将依赖项更新时间缩短了大约 2 个数量级。

  1. Uncheck "Use auto-import" in Preferences > Build, Execution, Deployment > Build Tools > sbt to prevent IntelliJ from auto updating imports on its ownPreferences > Build, Execution, Deployment > Build Tools > sbt取消选中“使用自动导入”以防止 IntelliJ 自行自动更新导入

在此处输入图片说明

  1. Add addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.3") to your project's build.sbt fileaddSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.3")到项目的build.sbt文件中
    • Or install it globally in ~/.sbt/1.0/plugins/build.sbt或者全局安装在~/.sbt/1.0/plugins/build.sbt
  2. Run sbt update on the command line在命令行上运行sbt update

If you see [error] java.lang.NoClassDefFoundError: org/vafer/jdeb/Console , then add the following to ~/.sbt/1.0/sbt-coursier.sbt .如果您看到[error] java.lang.NoClassDefFoundError: org/vafer/jdeb/Console ,则将以下内容添加到~/.sbt/1.0/sbt-coursier.sbt

import coursier.Keys._
classpathTypes += "maven-plugin"

See coursier issue #450 for more information about that error.有关该错误的更多信息,请参阅cousier issue #450

  1. (Optional) Re-enable auto-import from step 1, as subsequent transactional dependency updates may be faster. (可选)从第 1 步重新启用自动导入,因为后续的事务依赖更新可能会更快。

I meet the same problem! I delete the directory ~/.sbt/0.13, then it works.我也遇到了同样的问题!我删除目录~/.sbt/0.13,然后就可以了。 You can delete the sbt directory you used.您可以删除您使用的 sbt 目录。

What worked for me was to increase the memory for SBT inside IntelliJ.对我有用的是在 IntelliJ 中增加 SBT 的内存。 On my Mac: preference -> Build, Execution, Depoyment -> sbt then change "Maximum heap size" from 768MB to 2048MB and then everything was successfully imported after few minutes.在我的 Mac 上:首选项 -> 构建、执行、部署 -> sbt 然后将“最大堆大小”从 768MB 更改为 2048MB,然后几分钟后所有内容都成功导入。

Custom SBT version works for me.自定义 SBT 版本对我有用。

IntelliJ IDEA Preferences -> Build,Execution,Deployment -> Build Tools -> sbt -> Launcher IntelliJ IDEA Preferences -> Build,Execution,Deployment -> Build Tools -> sbt -> Launcher

Choose Custom选择自定义

自定义 sbt 截图

对我来说,只需检查use sbt shell for both build and imports

Had an older checked out project causing this issue.有一个较旧的签出项目导致此问题。 Did the usual rm -rf .idea + re-import but it kept getting stuck.通常的rm -rf .idea + 重新导入,但它一直卡住。 Tried all sorts of things, but when finally fixed it for me was not just deleting the top-level target folder, but instead doing尝试了各种方法,但是当最终为我修复它时不仅仅是删除顶级target文件夹,而是执行

find . -name target -type d -exec rm -rf {} \;

Next open / import went flawlessly.下一次打开/导入完美无缺。 (This was on 2018.1.5, 2018.1.6 and 2018.2 RC.) (这是 2018.1.5、2018.1.6 和 2018.2 RC。)

I have suffered from same problems after upgrade intelliJ to 2017.3 But it works fine now.将 intelliJ 升级到 2017.3 后,我遇到了同样的问题,但现在工作正常。

I think intelliJ couldn't pass the ' No proxy for ' option to sbt.我认为 intelliJ 无法将“无代理”选项传递给 sbt。 so, I added所以,我补充说

-Dhttp.nonProxyHosts="host1|host2" -Dhttp.nonProxyHosts="host1|host2"

option in File > Settings > Build, Excution, Deployment > sbt > VM parameters文件 > 设置 > 构建、执行、部署 > sbt > VM 参数中的选项

简单地取消选中“sbt 来源”对我来说就成功了

I was also facing this issue.我也面临这个问题。 Below two configurations worked for me.以下两种配置对我有用。 I tried to confirm this setting in many new sbt projects, for all it worked.我试图在许多新的 sbt 项目中确认这个设置,因为它有效。

(1) uncheck "Library sources" under "Project level settings" for Build Tools sbt in IDEA preferences (2) -Dhttp.nonProxyHosts="host1|host2" option in File > Settings > Build, Excution, Deployment > sbt > VM parameters (1)在IDEA首选项(2)-Dhttp.nonProxyHosts="host1|host2"选项中的文件>设置>构建、执行、部署>sbt>VM参数中为Build Tools sbt取消选中“Project level settings”下的“Library sources”

I hit similar issue but found it's related to waiting for locks我遇到了类似的问题,但发现它与等待锁有关

  • ~/.sbt/tool/sbt.boot.lock ~/.sbt/tool/sbt.boot.lock
  • ~/.ivy2/.sbt.ivy.lock ~/.ivy2/.sbt.ivy.lock

Maybe if killing IntelliJ IDEA and no one will release the lock files, the issue is resolved after deleting locks files manually可能如果杀掉IntelliJ IDEA没有人会释放lock文件,手动删除locks文件后问题解决

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

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