- 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:
- 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:
- 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 your self.
- It's possible to adjust a level of a library you want to create: Application Global or Project. If you plan to create other projects that involve it, select Application 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.
- Now everything's ready for the first HelloWorld application. Right-click src folder (or press Alt-Ins in default Windows IntelliJ IDEA keymap) and select Scala ObjectClass.
Image RemovedType HelloWorld in the appeared dialog Image Added
- 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.
- 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. IntelliJ IDEA expands this macro to a complete well-formed main() method body.
- 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. Note the tiny green mark on the HelloWorld object icon - it means that it can be run 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.
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 many more.