Setting up Scala in IntelliJ 11
Having just gone through the process of setting up Scala for use in IntelliJ, I thought it would be helpful to share the experience so that others find an easier route.
Environment
Mac OS X 10.8
JDK 1.7 (Oracle download)
Homebrew (http://mxcl.github.com/homebrew)
IntelliJ 11 (http://www.jetbrains.com/idea/)
Download Scala Plugin
IntelliJ > Preferences > Plugins > Browse Repositories... > Scala
Click Ok and allow IntelliJ to restart
Download Scala
In Terminal enter
brew install scala
Setup symbolic links for IntelliJ discovery process
ln -s /usr/local/Cellar/scala/2.9.2/libexec/src /usr/local/Cellar/scala/2.9.2/src
ln -s /usr/local/Cellar/scala/2.9.2/libexec/lib /usr/local/Cellar/scala/2.9.2/lib
Download Scala Documentation
Make directories in Scala home
mkdir -p /usr/local/Cellar/scala/2.9.2/doc/scala-devel-docs/apiDownload and Copy Manually
Unzip files from http://www.scala-lang.org/downloads/distrib/files/scala-docs-2.9.2.zipCopy contents of zip file to new directory
cp -r <path to unpacked zip root> /usr/local/Cellar/scala/2.9.2/doc/scala-devel-docs/api
or Download and Copy by Script
curl http://www.scala-lang.org/downloads/distrib/files/scala-docs-2.9.2.zip -o scala-docs.zip; unzip scala-docs.zip; cp -r scala-docs-2.9.2/* /usr/local/Cellar/scala/2.9.2/doc/scala-devel-docs/api; rm scala-docs.zip; rm -rf scala-docs-2.9.2
Create Project in IntelliJ
Here you are going to create a Java project from scratch as you normally would. However, in the last step, you will select Scala in the "Technologies" page.
In the Standard Distribution enter /usr/local/Cellar/scala/2.9.2
In the Compiler dropdown select scala-compiler
Click Ok and you are ready to create your first Scala object
Sidebar on IntelliJ/Scala Configuration
Scala and IntelliJ Facets
IntelliJ treats Scala as a Facet. If you are not familiar with Facets, these are add-on features/technologies to the base project. In IntelliJ, the base project is Java and Scala is Facet of that project. Therefore, if you need to modify Scala's configuration for your project, you will find that this under Module Settings > Facets.Module Dependencies
When you add the Scala Facet, IntelliJ should add the scala-library as a dependency for your module. That is, when you Scala installs two parts both contained in the /usr/local/Cellar/scala/2.9.2/libexec/lib directory: a compiler; and the runtime library.
In some case, IntelliJ does not add the scala-library as a dependency and therefore you will get compiler errors. In order to rectify this, simply manually add scala-library to your module dependencies.
Up Next: Speeding up Scala Compiles
Thanks for this!
ReplyDelete