Let’s see how to Install Scala Plugin in IntelliJ IDEA IDE tool and run the Spark Hello world example in Scala, IntelliJ IDE provides developers with editing and debugging support for Scala applications. IntelliJ IDEA is the most used IDE for Scala due to its early adaptation and good scala code competition.

IntelliJ IDE by default doesn’t come with a Scala plugin hence you need to install explicitly from settings.

If you already have IntelliJ IDE setup and wanted to just install the Scala plugin jump to the next section. In case if you wanted to install IntelliJ, follow the below steps.

Related: How to Setup Spark in IntelliJ Editor

1. IntelliJ IDEA Installation

IntelliJ IDEA comes with mainly two editions; community & ultimate. To run the scala application we will use the community edition, so download IntelliJ IDEA community edition.

  1. You can either download windows installer(.exe) or as a compressed zip (.zip) file based on your convenience. I’ve downloaded the .zip file.
Download IntelliJ IDE

2. Now, let’s unzip either using Winzip, 7-Zip, or any other zip extracts you have. I’ve used 7-Zip to extract the contents to the folder.

Extract IntelliJ IDEA

3. Move the extracted folder from Downloads to your working folder. In my case, I am moving it to c:apps.

4. Start IntelliJ IDE by running idea64.exe from C:appsideaIC-2020.2.1.winbinidea64.exe

2. Install Scala Plugin in IntelliJ

Start IntelliJ IDE by running idea64.exe from installation folder. I have installed IntelliJ at C:appsideaIC-2020.2.1.winbinidea64.exe and follow the below steps to install the Scala plugin.

Steps to install Scala Plugin in IntelliJ

  1. Open File > Settings (or using shot keys Ctrl + Alt + s )
  2. Select the Plugins option from the left panel. This brings you Feature panel.
  3. Click on Install to install the Scala plugin.
Install scala plugin in intellij
Install Scala Plugin on IntelliJ

4. After scala plugin installation completes, restart the IntelliJ IDE.

3. Create a Scala Project using scala-archetypes-simple In IntelliJ

Follow the below steps to create a Scala project using Scala archetype in IntelliJ (org.scala-tools.archetypes:scala-archetypes-simple)

  1. Select New Project to open New Project window.
Create Scala Project using archetypes

2. Select Maven from the left panel

3. Check option Create from archetype

4. Select org.scala-tools.archetypes:scala-archetypes-simple.

  • The archetype is a kind of templates that creates the right directory structure and downloads the required default dependencies. Since we have selected Scala archetypes, it downloads all Scala dependencies and enables IntelliJ to write Scala code.

5. In the next window, enter the project name. I am naming my project as scala-hello-world-example.

6. On next screen, review the options for artifact-id and group-id

7. Select Finish.

You will see the project created on IntelliJ and shows the project structure on left Project panel.

4. Setup Scala SDK

Now install Scala SDK, if you already have downloaded Scala you can point it to the local filesystem or you can download the Scala libraries from the IntelliJ itself.

  1. IntelliJ will prompt you as shown below to Setup Scala SDK.
Install Scala Plugin in IntelliJ

2. Select Setup Scala SDK, it prompts you the below window,

3. Select the create option.

Install Scala Plugin in intellij
nstall Scala Plugin in IntelliJ

4. From the next window select the Download option and

5. Choose the Scala version 2.12.12 (latest at the time of writing this article)

6. Make changes to pom.xml file

Now, we need to make some changes in the pom.xml file, you can either follow the below instructions or download the pom.xml file GitHub project and replace into your pom.xml file.

  1. First, change the Scala version to the latest version, I am using 2.12.12
 
 <properties>
    <scala.version>2.12.12</scala.version>
 </properties>

2. Remove following plugin

 
      <plugin>
        <groupId>org.scala-tools</groupId>
        <artifactId>maven-scala-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <scalaVersion>${scala.version}</scalaVersion>
          <args>
            <arg>-target:jvm-1.5</arg>
          </args>
        </configuration>
      </plugin>

7. Delete Unnecessary Files

Now delete the following from the project workspace.

  1. Delete src/test
  2. Delete src/main/scala/org.example.App
scala setup run intellij windows

If you have any questions or errors while installing Scala plugin on IntelliJ, please comment or ask me a question on Ask me section.

Happy Learning !!