scala IntelliJ 无法导入 sbt 项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47697141/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IntelliJ Cannot Import sbt Project
提问by radumanolescu
I have upgraded IntelliJ to version CE 2017.3 from a CE 2017.2.5, and now I cannot build my sbt project. The build gets stuck on the first step:
我已经将 IntelliJ 从 CE 2017.2.5 升级到 CE 2017.3 版本,现在我无法构建我的 sbt 项目。构建卡在第一步:
"Build: sync
MyProjName: syncing...
dump project structure from sbt"
I have deleted the .idea directory and the the MyProjName/project/targetdirectory. I did an sbt build from the command line, which worked.
Then I started IntelliJ again and tried to import MyProjName/build.sbtas a project. I have also logged out/in. Did this several times. The import never progresses past this step.
我已经删除了 .idea 目录和MyProjName/project/target目录。我从命令行做了一个 sbt 构建,它有效。然后我再次启动 IntelliJ 并尝试MyProjName/build.sbt作为项目导入。我也已注销/登录。这样做了几次。导入永远不会超过这一步。
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. Scala plugin 2017.3.10.
sbt 版本是 0.13.6。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)
回答by civic.LiLister
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. As shown in image below:
即,在 IntelliJ IDEA 中,清除 IDEA 首选项中 Build Tools sbt 的“项目级别设置”下的“库源”复选框。如下图所示:
回答by JPotts
The only way I could work around this was by running sbt clean compilein the SBT console/cmd line first, then refreshing the SBT project in IntelliJ.
我可以解决此问题的唯一方法是sbt clean compile首先在 SBT 控制台/cmd 行中运行,然后在 IntelliJ 中刷新 SBT 项目。
回答by radumanolescu
I have not found a way to make this work in IntelliJ Idea CE 2017.3, so I have reverted to CE 2017.2.5
我还没有找到在 IntelliJ Idea CE 2017.3 中完成这项工作的方法,所以我已经恢复到 CE 2017.2.5
回答by Cory Klein
IntelliJ appears to limit the efficiency of the already slow sbt update. I recommend using sbt-coursierinstead. 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.
IntelliJ 似乎限制了已经很慢的sbt update. 我建议改用sbt-coursier。它是专门为改进依赖更新时间而编写的,在我参与的一个大型项目中,将依赖更新时间缩短了大约 2 个数量级。
- Uncheck "Use auto-import" in
Preferences > Build, Execution, Deployment > Build Tools > sbtto prevent IntelliJ from auto updating imports on its own
- 取消选中“使用自动导入”
Preferences > Build, Execution, Deployment > Build Tools > sbt以防止 IntelliJ 自行自动更新导入
- Add
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.3")to your project'sbuild.sbtfile- Or install it globally in
~/.sbt/1.0/plugins/build.sbt
- Or install it globally in
- Run
sbt updateon the command line
- 添加
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.3")到您的项目build.sbt文件- 或者全局安装
~/.sbt/1.0/plugins/build.sbt
- 或者全局安装
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 #450for more information about that error.
有关该错误的更多信息,请参阅cousier issue #450。
- (Optional) Re-enable auto-import from step 1, as subsequent transactional dependency updates may be faster.
- (可选)从第 1 步重新启用自动导入,因为后续的事务依赖更新可能会更快。
回答by Marcio Tedesco
- Open a terminal inside IDEA by pressing AltF12or use sbt shell
- Run
sbt- if it is first time it will take some time. - Run
clean - Run
compile- it will download dependencies you have in your project. - Close IDEA project (
File->Close Project) and open it again.
- 通过按下AltF12或使用sbt shell在 IDEA 中打开一个终端
- 运行
sbt- 如果是第一次,则需要一些时间。 - 跑
clean - 运行
compile- 它将下载您在项目中的依赖项。 - 关闭 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 projectagain. When you try to use import in the middle of a sync it gets stuck with dump project structure from sbtmessage.
注意:如果它要求在屏幕右下角导入 activate Enable auto-import,如果您不喜欢保持启用状态(像我一样)按Import,取消同步,然后Refresh sbt project再次。当您尝试在同步过程中使用 import 时,它会被sbt消息中的转储项目结构卡住。
The Refresh sbt projectis located at this corner of the Build Sync window - highlighted below:

回答by xiang liu
I meet the same problem! I delete the directory ~/.sbt/0.13, then it works. You can delete the sbt directory you used.
我也遇到了同样的问题!我删除目录~/.sbt/0.13,然后就可以了。您可以删除您使用的 sbt 目录。
回答by marios
What worked for me was to increase the memory for SBT inside IntelliJ. 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.
对我有用的是在 IntelliJ 中增加 SBT 的内存。在我的 Mac 上:首选项 -> 构建、执行、部署 -> sbt 然后将“最大堆大小”从 768MB 更改为 2048MB,然后几分钟后所有内容都成功导入。
回答by Huang Zehai
Custom SBT version works for me.
自定义 SBT 版本对我有用。
IntelliJ IDEA Preferences -> Build,Execution,Deployment -> Build Tools -> sbt -> Launcher
IntelliJ IDEA 首选项 -> 构建、执行、部署 -> 构建工具 -> sbt -> 启动器
Choose Custom
选择自定义


回答by orhaneee
For me, simply checking use sbt shell for both build and importsworked.
对我来说,简单的检查use sbt shell for both build and imports工作。
回答by nibblonian
Had an older checked out project causing this issue. Did the usual rm -rf .idea+ re-import but it kept getting stuck. Tried all sorts of things, but when finally fixed it for me was not just deleting the top-level targetfolder, but instead doing
有一个较旧的签出项目导致此问题。做了通常的rm -rf .idea+重新导入,但它一直卡住了。尝试了各种方法,但是当最终为我修复它时不仅仅是删除顶级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。)

