Every Scala developer out there knows SBT is the default build tool for Scala but there may be some situations limiting you to sticking with the famous build tool for Java: Apache Maven. Haven’t come across a reason to use Maven for Scala projects yet? Keep using SBT. However, if your team is using Apache Maven because it works well with their CI server or because they have a well-established development environment with Apache Maven, you have no choice and this article is here to help you.


Requirements

After installing IntelliJ IDEA and Apache Maven, set up Scala in IntelliJ IDEA following this article: How to Setup Scala in IntelliJ IDEA?


Create Scala Project using Maven Command Line

Creating a Scala project using Apache Maven in the command line is super easy. Just run the following command, answer the questions in the interactive shell and you are good to go.

mvn archetype:generate -DarchetypeGroupId=net.alchim31.maven -DarchetypeArtifactId=scala-archetype-simple

Something works doesn’t necessarily mean that there is nothing else better. Why should we create a project in the terminal and then switch to the IntelliJ IDEA for development? Instead, we can create the Scala project with Macen in IntelliJ IDEA itself.


Add Scala Maven Archetype

For those who have to create Scala projects with Apache Maven frequently, it is convenient to add the Scala Maven archetype to IntelliJ IDEA. It is a one-time effort but will payoff you every time you want to create a new project.

Step 1:
Open the IntelliJ IDEA’s New Project dialog and select “Maven Archetype” from the left panel.

Step 2:
Click on the “Add…” button next to the Archetype text box.

Step 3:
In the opened dialog, enter the following values and click OK:

GroupIdnet.alchim31.maven
ArtifactIdscala-archetype-simple
Version1.7

Create Scala Project with Maven in IntelliJ Idea

Step 1:
Open the IntelliJ IDEA’s New Project dialog and select “Maven Archetype” from the left panel.

Step 2:
Enter a project name. Select the Archetype “net.alchim31.maven:scala-archetype-simple” and the Version “1.7”. Expand the advanced settings and change the group id according to your organization. Finally click on the “Create” button.


Run Scala Project

If you have already installed the IntelliJ IDEA Scala Plugin as required in the Requirements section, your project is ready to use. In case you didn’t install the plugin earlier, follow the How to Setup Scala in IntelliJ IDEA article and install the Scala plugin.

Run the App and see if it prints Hello World in the terminal. Now onwards you can create Scala projects with Apache Maven from the IntelliJ IDEA itself.

Have you found this article useful? Please let me know below in the comments. Knowing someone found my articles useful motivates me to write more. Also, comment below if you face any issues with following this article or getting it working. I will try my best to help you resolve the problem. The Java Helps community is also willing to help each other and grow together.


Share.
Exit mobile version