71

I have Intellij ultimate 11.1, with the scala plugin installed.

I installed scala 2.9.2 using homebrew, which put scala in:

/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:

enter image description here

enter image description here

enter image description here

enter image description here

Can someone help me fix these issues, why didn't the scala plugin make this work out of the box? :)

t0r0X
  • 4,212
  • 1
  • 38
  • 34
Blankman
  • 259,732
  • 324
  • 769
  • 1,199

8 Answers8

86

You need to specify /usr/local/Cellar/scala/2.9.2/libexec directory on your first screenshot. This is Mac brew specific, the same case is valid for grails installed via brew.

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.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • 3
    thanks, now it says with a yellow sign "version 2.9.2, no doc/scala-devel-...", how do I fix that? – Blankman Jun 01 '12 at 01:03
  • 11
    Download the documentation from http://www.scala-lang.org/downloads/distrib/files/scala-docs-2.9.2.zip, unpack in some directory, modify JavaDocs directory in the `scala-library` in IDEA module libraries to the directory where you have unpacked the documentation (this directory must have `scala` subdirectory with `.html` files. – CrazyCoder Jun 01 '12 at 04:44
  • I came here trying to find where I should download the docs for the scala download from the installation from the web site. I instead used brew to install it and then it tells you a scala home to use for IntelliJ. – Egwor Dec 27 '13 at 12:30
  • 3
    Even with `brew install scala --with-docs` pointing at `libexec` will give you doc errors. Update your homebrew and then point at `/usr/local/Cellar/scala/2.XX.X/idea` to get the doc errors to go away. – Ashley Jan 16 '14 at 20:14
71

Updated for 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.

Download Scala Plugin

IntelliJ > Preferences > Plugins > Browse Repositories... > Scala Click Ok and allow IntelliJ to restart

Download Scala

In Terminal enter

brew install scala --with-docs

Setup symbolic links for IntelliJ discovery process

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

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 Use Scala Distribution enter /usr/local/Cellar/scala/<version>

In the Compiler dropdown select scala-compiler

Click Ok and you are ready to create your first Scala object

For reference -> http://scalacookbook.blogspot.com/2012/09/scala-for-intellij.html

juice
  • 1,651
  • 15
  • 11
  • This is great! When I follow this it also complains that there is no SDK. Where are the SDK folder? – Christopher Käck Feb 25 '13 at 12:58
  • If my memory serves me correct, the SDK is still Java. The Scala piece is still just a facet of the main project. That is, there is no "pure" Scala project setup – juice Mar 19 '13 at 04:14
  • 1
    Would it be worth updating this answer with "--use-docs" to get the documentation, then it'd be the authoritive answer for those who search for the answer? – David Roussel Jul 14 '13 at 13:41
  • Also, is it worth updating the brew formula to add in the symlinks automatically? – David Roussel Jul 14 '13 at 13:43
  • Good suggest about the --with-docs (use-docs). I went ahead and changed this and updated some other items for 11.1.5. – juice Jul 20 '13 at 20:16
  • on scala 2.11.6 and intellij 14.1 I had to do as suggested here: http://stackoverflow.com/a/29841210/112440 and use the path /usr/local/Cellar/scala/2.11.6/idea/lib – Yonatan Karni Sep 21 '15 at 12:38
20

The latest Brew has already realized this problem and created automatic symlinks upon installing Scala.

Firstly, install Scala with Documentation

brew install scala --with-docs

Secondly, provide the following path in IntelliJ

/usr/local/opt/scala/idea
16

Rather than downloading the docs separately you can use the --with-docs option when installing scala with homebrew:

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.

David Keen
  • 613
  • 7
  • 11
7

I'm just found another way to configure scala with intelJIdea. If scala installed with brew then just write in terminal:

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.

Dmitry Zagorulkin
  • 8,370
  • 4
  • 37
  • 60
3

Now is 2021 year. my (latest) environment is:

  • IntelliJ IDEA: IntelliJ IDEA 2020.3.2 (Community Edition)
  • OS: macOS 10.14.6

Steps to setup Scala using IntelliJ IEA

in Mac

  • install scala using brew
    • brew install scala

in IntelliJ

  • install Scala plugin
    • IntelliJ IDEA->Preferences->Plugins->search: scala-> Search in Marketplace->Install->Restart IDE
      • enter image description here
  • configure Java JDK + configure Scala SDK: when first time open *.scala file, will notice you:
    • Project JDK is not defined
      • click Setup SDK -> choose (your installed) Java 11
        • enter image description here
    • No Scala SDK in module
      • clcik Setup Scala SDK
        • Add Scala Support-> Use library -> Create -> Select JAR's for the new Scala SDK -> Click and choose Brew -> OK
          • enter image description here
        • Add Scala Support-> Use library -> (then) selected: scala-sdk-2.13.5 -> OK
          • enter image description here

finally can happy debug scala (file's class's main function):

enter image description here

crifan
  • 12,947
  • 1
  • 71
  • 56
1

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:

/usr/local/Cellar/scala/[insertversion]/libexec

Here is what I see in IntelliJ when I created a new project with these settings

I tested compiling a Hello World program via this and it compiled correctly to the console.

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.

Dhruv Ghulati
  • 2,976
  • 3
  • 35
  • 51
-2

Change /usr/local/Cellar/scala/2.9.2 to /usr/local/Cellar/scala/ and you are good to go.

ajknzhol
  • 6,322
  • 13
  • 45
  • 72