Using IntelliJ with scala

Can someone recommend a good reference (book/article/video) about how to use IntelliJ in Scala development? There are plenty of videos about how to install it. I think people who have used it a long time don’t remember how unintuitive it can be for beginners.

2 Likes

Good question. I’d like to use intellij also but dred having to spend time learning another ide . I remember learning eclipse years ago and there were some great online tutorials. Not the case for intellij for some reason

2 Likes

Remember to install the Scala-pluging, else the keymap is useful:

Is there a specific use-case you’re having problems with?

1 Like

If you’re already fluent with Eclipse (Java or Scala), you may prefer to switch to Eclipse key bindings in “File → Settings → Keymap”. (However, you’ll probably want to individually pimp the bindings for some actions that don’t have an equivalent in Eclipse.)

2 Likes

Hi Jimka,
I am beginner too and I am enjoying that site. http://allaboutscala.com/
I think that big issue is about dependencies but after we can understand that part, tool will be a piece of cake

2 Likes

No, not familiar with eclipse at all. I’m a long time emacs user. The emacs Scala support seems to be extraordinarily good, however it requires that you already be a Scala expert before you begin. It’s not really suitable for scala-beginners as far as I can tell.

Yeah sorry there isn’t great instruction. Get the Scala plugin for IntelliJ and generally start projects as SBT projects on the command line and under New Project load them as existing source and find the build.sbt file and double click it. Choose the automatic options in that dialog.

One great thing is to create a Scala worksheet under New. This will allow you to try out interactive Scala with type inference and solved values on the right and your code on the left. This is like the REPL, but graphical.

Hi benitito, I don’t see worksheet under New as you predict. Perhaps it is obvious to a long time user, but it’s not so obvious to the novice.

That makes me wonder if you have the Scala plugin installed. Compare to my view:

1 Like

Funnily, I opened this post not long after a small rant on Twitter about the woes of trying to setup Scala development in Emacs. Whilst the basic things like SBT and Scala-mode, and in particular, Ensime, are great and work pretty much out of the box (read package), the rest of the basic configuration is a hellish journey into a quagmire of outdated advice, poor documentation, and a heap of lisp code (and that’s just basic setup). The later Emacs (26 / 27) don’t even consider global line number advantageous and have it in a minor mode, which one needs to setup with a hook for every other mode its needed in (like scala-mode)

Other things like, auto bracket closing, quote closing, indentation, formatting, code completion, everything the modern developer really needs, (as well as good debugging tools (line numbers perhaps?)); these are all buried deep in an ecosystem of setups, packages, and lisp codes, making it truly inefficient as an IDE until mastery is achieved.

I have spent a while on trying both Emacs and vim but ALL of that time is spent configuring and not coding. Thus back to IntelliJ I went and was up and running in Scala with all the bells and Whistles in an hour. The SBT integration with the Scala Plugin gives you all the discerning developer needs, its easy as pie (well compared to the spaghetti of Emacs).

If you must have your Emacs / Vim finger aerobics, these can easily be configured (in fact, IntelliJ has a vim plugin available), you could even spend hours making it look Emacs like!

The moral here is, IntelliJ in my opinion is one of the best Scala IDE’s available, you can get up and running in the Community Edition without having to fork out the money for the Ultimate. From setup its Easy to get Scala up and Running (provided you have SBT installed on your system, oh and the Documentation? JetBrains know how to do that, and you can get it straight from inside the IDE too, most of its in Human speak!

I would fully recommend giving it a go, I think even as an Emacs user :wink: you will be surprised!

2 Likes

I’m pretty sure the scala plugin is setup.

Perhaps it is related to what in the directory tree highlighted.
I tried to highlight the scala directory, and indeed saw the Scala Worksheet option,
and was able to open a worksheet.
Thereafter, even when I highlight the source window, exactly as in the post above,
I also see the Scala Worksheet option.
It is mysterious.

55

OK, let me ask another question. Not sure if it is an IntelliJ question or a Scala question.
I’ve setup a simple project with some tests.
When I implement a new function in the project, I implement some tests in the testing file.

And I can run my tests by selecting JimkaSuite and pressing the play button.

07

After doing this I see a log of the tests that are run.

15

How does IntelliJ know what to display, which tests there are and whether they’ve passed?
Does the FunSuite class that I’m using know about IntelliJ? Or is it printing stdout which
the scala plugin is watching and parsing? Or how is it working?

So far I have been able to use Eclipse with Scala. It seems quite simple to do. THere is a special Eclipse dedicated to just Scala. At least from the point of view of a beginner, a combination of Eclipse and REPL , seem to work find ( and maven also for dependecies )

1 Like

I think like on the Java and Python sides, IntelliJ is looking for certain test stuites and then implementing the nice bahavior. I love that. You can right click and easily run one test too. Another cool thing: Right click a method and choose Go To > Test. If it doesn’t exist yet, a dialog will pop up to help create the framework for the test.

Why do they push SBT instead of maven ( which seems a lot easier to use to me ). I have yet to use SBT since I have started studying Scala; I am coming from a java background so that might be the reason for just using maven )

The reason I use sbt is because it was what was used in the Coursera Scala courses.

When you have used maven for years, of course it is easier to use than something you have never used before. Not that I can guarantee that you would eventually find sbt easier to use than maven if you use both a lot… I do find however that sbt provides a more pleasant development experience than maven when developing in Scala, especially if you choose not go with a full IDE.

To start with, I used Maven but only for a short while before switching to sbt. It’s OK if you get IntelliJ take care of it. When I would have problems (and you will have problems because what Scala is trying to do is quite powerful and a little revolutionary in the end by marrying OO and functional), I would peak at sbt and I eventually put a couple of hours into the docs. sbt is way more powerful and easier to work with at a glance when checking something than Maven once you learn a little bit. Then one day when tired of how long IntelliJ was taking to build and run, I pulled up a shell and compiled and ran with sbt. Faster! Alot. I just use that now and I’m never worried about compiling errors from IntelliJ or dependency problems or type checking inconsistencies with IntelliJ and Twirl sometimes. Extensive Twirl fragmentation with Play! can sometimes confuse IntelliJ.

I will take a look at sbt. I am also curious as to how it handles those internal corporate firewalls, and artifactories. You see, from what i see, maven is a build tool and dependent revolver that requires almost no effort on the part of the developer. The developer only spends time developing scala application, not sbt (or eclipse) applications

Keep in mind, sbt uses Maven repositories under the hood. So the answer to:

is, essentially, exactly the same as Maven. The syntax is a bit different, but the semantics are identical.

You’re worrying way too much about this. While sbt is complex for complex apps, it’s basically push-button for simpler ones. There’s an sbt new command that will create a functioning starting sbt file from an giter8 template, and from there you just tweak it as necessary. Until and unless you get into big, complex, multi-project builds, it’s generally straightforward. (And once you’re into a multi-project build, no tool is actually simple.)

2 Likes