[英]Setting up scala with IntelliJ
I have Intellij ultimate 11.1, with the scala plugin installed.我有 Intellij Ultimate 11.1,安装了 Scala 插件。
I installed scala 2.9.2 using homebrew, which put scala in:我使用自制软件安装了 Scala 2.9.2,它将 Scala 放入:
/usr/local/Cellar/scala/2.9.2>
>which scala
/usr/local/bin/scala
>scala -version
Scala code runner version 2.9.2 -- Copyright 2002-2011, LAMP/EPFL
Creating a new java module project, I get this:创建一个新的java模块项目,我得到这个:
Can someone help me fix these issues, why didn't the scala plugin make this work out of the box?有人能帮我解决这些问题吗,为什么 scala 插件不能让这个工作开箱即用? :)
:)
You need to specify /usr/local/Cellar/scala/2.9.2/libexec
directory on your first screenshot.您需要在第一个屏幕截图上指定
/usr/local/Cellar/scala/2.9.2/libexec
目录。 This is Mac brew
specific, the same case is valid for grails
installed via brew
.这是 Mac
brew
特定的,同样的情况适用于通过brew
安装的grails
。
Standard Scala distribution download has different layout which IDEA understands correctly, brew
is creating libexec
directory where it writes /lib
and /src
directories expected by IDEA.标准Scala 发行版下载具有 IDEA 正确理解的不同布局,
brew
正在创建libexec
目录,在其中写入 IDEA 期望的/lib
和/src
目录。
Updated for Intellij 11.1.5针对 Intellij 11.1.5 更新
Here's a step by step for any of those who are trying to get Scala in IntelliJ up and running.对于那些试图在 IntelliJ 中启动和运行 Scala 的人,这里有一个分步指南。
Download Scala Plugin下载 Scala 插件
IntelliJ > Preferences > Plugins > Browse Repositories... > Scala Click Ok and allow IntelliJ to restart IntelliJ > 首选项 > 插件 > 浏览存储库... > Scala 单击确定并允许 IntelliJ 重新启动
Download Scala下载 Scala
In Terminal enter在终端输入
brew install scala --with-docs
Setup symbolic links for IntelliJ discovery process为 IntelliJ 发现过程设置符号链接
ln -s /usr/local/Cellar/scala/<version>/libexec/src /usr/local/Cellar/scala/<version>/src
ln -s /usr/local/Cellar/scala/<version>/libexec/lib /usr/local/Cellar/scala/<version>/lib
mkdir -p /usr/local/Cellar/scala/<version>/doc/scala-devel-docs
ln -s /usr/local/Cellar/scala/<version>/share/doc/scala /usr/local/Cellar/scala/<version>/doc/scala-devel-docs/api
Create Project in IntelliJ在 IntelliJ 中创建项目
Here you are going to create a Java project from scratch as you normally would.在这里,您将像往常一样从头开始创建 Java 项目。 However, in the last step, you will select Scala in the "Technologies" page.
但是,在最后一步中,您将在“技术”页面中选择 Scala。
In the Use Scala Distribution enter /usr/local/Cellar/scala/<version>
在Use Scala Distribution 中输入
/usr/local/Cellar/scala/<version>
In the Compiler dropdown select scala-compiler
在编译器下拉列表中选择
scala-compiler
Click Ok and you are ready to create your first Scala object单击 Ok,您已准备好创建您的第一个 Scala 对象
For reference -> http://scalacookbook.blogspot.com/2012/09/scala-for-intellij.html供参考 -> http://scalacookbook.blogspot.com/2012/09/scala-for-intellij.html
The latest Brew has already realized this problem and created automatic symlinks upon installing Scala.最新的 Brew 已经意识到这个问题,并在安装 Scala 时创建了自动符号链接。
Firstly, install Scala with Documentation首先,使用文档安装 Scala
brew install scala --with-docs
Secondly, provide the following path in IntelliJ其次,在IntelliJ中提供如下路径
/usr/local/opt/scala/idea
Rather than downloading the docs separately you can use the --with-docs
option when installing scala with homebrew:在使用自制软件安装 scala 时,您可以使用
--with-docs
选项,而不是单独下载文档:
brew install scala --with-docs
Then in IntelliJ point your JavaDocs path in the scala-library to /usr/local/Cellar/scala/2.9.2/share/doc
.然后在 IntelliJ 中将 Scala 库中的 JavaDocs 路径指向
/usr/local/Cellar/scala/2.9.2/share/doc
。
I'm just found another way to configure scala with intelJIdea.我刚刚找到了另一种使用 intelJIdea 配置 scala 的方法。 If scala installed with brew then just write in terminal:
如果用 brew 安装了 Scala,那么只需在终端中写入:
brew info scala
you will see smth like that:你会看到这样的:
scala: stable 2.11.4 (bottled)
http://www.scala-lang.org/
/usr/local/Cellar/scala/2.11.4 (3401 files, 433M) *
Built from source with: --with-docs
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/scala.rb
==> Options
--with-docs
Also install library documentation
--with-src
Also install sources for IDE support
==> Caveats
To use with IntelliJ, set the Scala home to:
/usr/local/opt/scala/idea
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
Then just include /usr/local/opt/scala/idea
into your idea config panel.然后只需将
/usr/local/opt/scala/idea
到您的想法配置面板中。
I am using Yosemite, and the following worked for me.我正在使用优胜美地,以下对我有用。
brew install scala --with-docs
Then I tested IntelliJ by creating a new project, using the Java SDK, and for compiler putting in:然后我通过创建一个新项目、使用 Java SDK 和编译器输入来测试 IntelliJ:
/usr/local/Cellar/scala/[insertversion]/libexec
Here is what I see in IntelliJ when I created a new project with these settings这是我使用这些设置创建新项目时在 IntelliJ 中看到的内容
I tested compiling a Hello World program via this and it compiled correctly to the console.我测试了通过这个编译一个 Hello World 程序,它正确编译到控制台。
Note, I ignored what @Zagorulkin said above even though it seems logical that if Homebrew is saying so my compile path should be different to the above.请注意,我忽略了@Zagorulkin 上面所说的内容,即使 Homebrew 所说的是合乎逻辑的,所以我的编译路径应该与上面的不同。
Now is 2021 year.现在是 2021 年。 my (latest) environment is:
我的(最新)环境是:
IntelliJ IDEA
: IntelliJ IDEA 2020.3.2 (Community Edition)
IntelliJ IDEA
: IntelliJ IDEA 2020.3.2 (Community Edition)
OS
: macOS 10.14.6
OS
: macOS 10.14.6
brew install scala
Scala
pluginScala
插件
Java JDK
+ configure Scala SDK
: when first time open *.scala
file, will notice you:Java JDK
+ 配置Scala SDK
:第一次打开*.scala
文件时,会注意到:
Setup Scala SDK
Setup Scala SDK
Add Scala Support
-> Use library
-> Create
-> Select JAR's for the new Scala SDK
-> Click and choose Brew
-> OK
Add Scala Support
-> Use library
-> Create
-> Select JAR's for the new Scala SDK
-> 单击并选择Brew
-> OK
Add Scala Support
-> Use library
-> (then) selected: scala-sdk-2.13.5 -> OK
Add Scala Support
-> Use library
-> (then) selected: scala-sdk-2.13.5 -> OK
finally can happy debug scala (file's class's main
function):终于可以愉快的调试scala了(文件类的
main
函数):
将/usr/local/Cellar/scala/2.9.2
更改为/usr/local/Cellar/scala/
就可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.