Child pages
  • Getting Started with IntelliJ IDEA Scala Plugin
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 28 Next »

This page is IN PROGRESS.

Icon

In the meanwhile, please, use http://devnet.jetbrains.net/thread/290032

Before You Begin

Currently, IntelliJ IDEA Scala plugin is in beta stage and is being actively developed. Here is the list of what you will need to try it:

Setting up the Environment

After you have downloaded, 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.
  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. If everything is OK, there should be Scala plugin, listed in black, with a tick mark next to its name. All this means 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.
    Icon

    There is an alternative way to install the Scala plugin.Download the Scala plugin from the Nightly Builds page and unzip the archive to the directory <user home>/.IntelliJIdea<xx>/config/plugins.
    After that, run IntelliJ IDEA.

Creating a Project

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. Here you choose to create a new project from scratch:
  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, and the src directory that will store your source code:
      
  3. On top of that, select Scala on the Select Desired Technologies. By default all necessary jars will be downloaded automatically, but you also may pick them from already existing IDEA library or a secret place on your hard drive. Note the missing Scala API documentation - if you want to have the possibility to view documentation, you have to download it yourself.
  4. It's possible to adjust a level of a library you want to create: Global or Project. If you plan to create other projects that involve it, select Global - it lets you share it anywhere on the current machine. Otherwise you can go with Project - it does not really matter for this example.
  5. Now, when the project is ready, it is advisable to explore its settings. To do that, on the main toolbar, click . In the Project Structure dialog, click Modules, and then select the Dependencies tab:

    As you see, IntelliJ IDEA has automatically added the Scala compiler library to the list of module dependencies.

Creating Source Code

Now everything is ready for the first HelloWorld application.

  1. Right-click src folder (or press Alt-Ins in default Windows IntelliJ IDEA keymap) and select Package. Type the package name helloworld. Then, right-click the newly created package and choose Scala Class on the context menu:
  2. In the dialog box that opens, select the type of the Scala entity to be created - in our case, let it be Scala Object, type HelloWorld as the object name, and click OK. Here is our first Scala object.
  3. Now, we're going to make it runnable. There're several ways to achieve that. First off, we can extend the default scala.Application trait. With IntelliJ IDEA advanced code completion (in this case, the Scala Class Names) we don't have to type everything by ourselves. App plus Ctrl+Space gives you neat a and quick choice (see the picture below).

    Or, we can use a more Java-like approach: create main() method inside of object body. Again, IntelliJ IDEA lends us a hand with Live Templates. All we do is type main and press Tab (or press Ctrl+J in the default Windows IntelliJ IDEA keymap, and select main from the suggestion list). IntelliJ IDEA expands this macro to a complete well-formed main() method body.
  4. 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 (on default Windows keymap). Good news is that it works equally well for Scala applications.
    All we have to do is to type the code that displays the trivial Hello World message and then press Ctrl+Shift+F10 - or right-click the editor background and choose Run HelloWorld.main on the context menu. The application output is displayed in the console.
     

     
Icon

You can also turn your Scala object into a script. Just remove all declarations from the file, leave the executable statement only - println("Hello, World!"), and run the script as described above.

This concludes the getting started with Scala IntelliJ IDEA 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 interoperability which includes refactorings, coding assistance and much more.

 

  • No labels