In this tutorial, we’ll see how to build a minimal Scala project using IntelliJIDE with the Scala plugin. In this guide, IntelliJ will download Scala for you.
Installation
IntelliJ IDEA 2018.3.6. Using macOS Mojave Version 10.14.4 and pressing ⌥ F12 (Alt+F12) will open Sound preferences. A solution without changing the current keymap is to use the command above with the key fn. Fn ⌥ F12 (fn+Alt+F12) will open the Terminal. And you can use Shift Esc to close it. Out of the box, IntelliJ IDEA provides a comprehensive feature set including tools and integrations with the most important modern technologies and frameworks for enterprise and web development with Java, Scala, Groovy and other languages.
- Make sure you have the Java 8 JDK (also known as 1.8)
- Run
javac -version
on the command line and make sure you seejavac 1.8.___
- If you don’t have version 1.8 or higher, install the JDK
- Run
- Next, download and install IntelliJ Community Edition
- Then, after starting up IntelliJ, you can download and install the Scala plugin by following the instructions onhow to install IntelliJ plugins (search for “Scala” in the plugins menu.)
When we create the project, we’ll install the latest version of Scala.Note: If you want to open an existing Scala project, you can click Openwhen you start IntelliJ.
Creating the Project
- Open up IntelliJ and click File => New => Project
- On the left panel, select Scala. On the right panel, select IDEA.
- Name the project HelloWorld
- Assuming this is your first time creating a Scala project with IntelliJ,you’ll need to install a Scala SDK. To the right of the Scala SDK field,click the Create button.
- Select the highest version number (e.g. 2.13.5) and click Download. This mighttake a few minutes but subsequent projects can use the same SDK.
- Once the SDK is created and you’re back to the “New Project” window click Finish.
Writing code
- On the Project pane on the left, right-click
src
and selectNew => Scala class. If you don’t see Scala class, right-click on HelloWorld and click on Add Framework Support…, select Scala and proceed. If you see Error: library is not specified, you can either click download button, or select the library path manually. If you only see Scala Worksheet try expanding thesrc
folder and itsmain
subfolder, and right-click on thescala
folder. - Name the class
Hello
and change the Kind toobject
. - Change the code in the class to the following:
Running it
- Right click on
Hello
in your code and select Run ‘Hello’. - You’re done!
Experimenting with Scala
A good way to try out code samples is with Scala Worksheets Tim allen actor twitter.
- In the project pane on the left, right click
src
and select New => Scala Worksheet. - Name your new Scala worksheet “Mathematician”.
- Enter the following code into the worksheet:
As you change your code, you’ll notice that it gets evaluatedin the right pane. If you do not see a right pane, right click on your Scala worksheet in the Project pane, and click on Evaluate Worksheet. Citrix workspace 19.03.
Next Steps
![Idea Idea](/uploads/1/1/7/9/117936306/767305880.png)
Now you know how to create a simple Scala project which can be usedfor starting to learn the language. In the next tutorial, we’ll introducean important build tool called sbt which can be used for simple projectsand production apps.
Up Next: Building a Scala Project with IntelliJ and sbt