Child pages
  • Getting Started with IntelliJ IDEA Scala Plugin

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

For now Currently, IntelliJ IDEA Scala plugin for IntelliJ IDEA is in a stage of active development. Its last versions are available for IntelliJ IDEA EAP. So, to start, first let's download last EAP beta stage and is being actively developed. Here is the list of what you will need to try it:

...

...

In plugin manager window we choose Scala plugin. One could use search line to simplify this process. Clicking with right mouse button on it, we install it and restart IDEA to apply changes (we have to start it manually after shutdown).
Image Removed
 
After stratup we can notice that Scala plugin appeared in the list of installed plugins. So, now we are ready to create our first Scala project in IntelliJ IDEA.  Click Create New Project on Welcome page. Choose Create project from scratch. Let first module will be Java Module.
 
Image Removed
 
In the list of desired technologies mark Scala checkbox and click to button with dots to adjust our Scala SDK for compilation and using Scala libraries. Here we should point to installation directory of Scala programming language as follows.

 
Image Removed
 
Click finish and IDEA asks, what type of library we want to create: Application-level or Project level one? Main difference is that project library settings will be saved in project file, which may be useful to share same settings between several developers. Application-level library will be visible to attach for all projects on current machine.

Note: In near-term future we're going to make configuration process more flexible to not gather all scala-related jars in all library. It's crucial moment for projects like liftweb applications, which being inported from Maven repository may contain Scala jars separated by various libraries.
So, we just adjusted all necessary details to start writing our HelloWorld application. To create it right-click After you have download, installed and configured all the prerequisites, follow this simple procedure to get the Scala plugin up and running.

  1. Run IntelliJ IDEA. On the Welcome Screen, click Open Plugin Manager.
  2. Click Available tab and type Scala in the Search box to quickly locate plugin in the list.
    Image Added
  3. Right-click plugin name, select Download and Install from the menu, and restart IntelliJ IDEA to apply the changes.
  4. After IntelliJ IDEA is back, open Plugin Manager again to examine the list of installed plugins.
    Note

    If everything is OK, there should be Scala plugin, listed in black, with a tick mark next to its name, all this meaning the plugin is installed, enabled and is working OK. If there's no tick mark, or plugin name is listed in red, or you can't find it at all - there may be some problem you need to address, like getting the latest IntelliJ IDEA EAP version.

If everything is fine, you're ready to create the Scala project with IntelliJ IDEA.

  1. Back to the Welcome Screen, click Create New Project. The good old IntellIJ IDEA New Project wizard apperas.
    Image Added
  2. All you need is a Java Module with a name that makes sense, located somewhere you can find it later without spending a whole day digging through your entire hard drive.
    On top of that, pick Scala on the Select Desired Technologies step and specify the path where you installed Scala SDK.
    Image Added
     
  3. After you complete the wizard, IntelliJ IDEA prompts you whether you want to create an Application or Project level library for the Scala SDK you added. If you plan to create other projects that involve it, select Application - it lets you share it anywhere on the current machine. Otherwise you can go with Project - it does not really matter for this example.
Note

In the nearest future we're going to streamline the configuration process to avoid putting all scala-related jars in a single library. This should simplify developing liftweb-like applications, imported from Maven repositories that may contain various Scala jars scattered around in different libraries.

 

  1. Now everything's ready for the first HelloWorld application. Right-click src folder (or press Alt-Ins in default Windows IntelliJ IDEA keymap)

...

  1. and

...

  1. select Scala Object.

...

  1. Image Added

...

  1. Type

...

  1. HelloWorld

...

  1. in

...

  1. the appeared dialog

...

  1. and

...

  1. click OK. Here is our first Scala object.

...

  1. Now, we're going to make it runnable.

...

  1. There're several ways to achieve that. First off, we can extend the default scala.Application trait

...

  1. . With IntelliJ IDEA advanced code completion (in this case, the Scala Class Names) we don't have to type

...

  1. everything by ourselves. App plus Ctrl+Space gives you neat a and quick choice (see the picture below).
    Image Added
    Or, we can use a more Java-like approach: create main() method inside of object body.

...

  1. Again, IntelliJ IDEA lends us a hand with Live Templates. All we do is type main and press Tab. IntelliJ IDEA expands this macro to a complete well-formed main() method

...

  1. body.

...

  1. Image Modified

...

  1. Let's teach the application to do some work. If you're familiar with IntelliJ IDEA, you should probably be aware of that running a simple Java application is just a matter of pressing Ctrl-Shift-F10 (

...

  1. on default Windows keymap).

...

  1. Good news is that it works equally well for Scala applications. Note the tiny green mark on the HelloWorld object icon - it means that it can be run

...

  1. just as a native java application.
    All we have to do is to type the code that displays the trivial Hello World message and then press Ctrl-Shift-F10. The application output is displayed in the console.
     
    Image Modified
     

...

  1. This concludes the getting started with Scala

...

  1. IntelliJ IDEA

...

  1. plugin at the first glance. Hope it gives you a good kick to start exploring it for yourself, and, of course, reading this space - you can find more useful information about other helpful plugin features, like Java/Scala cross-language

...

  1. interoperability which includes refactorings,

...

  1. coding assistance and many

...

  1. more.