Start with an Erlang project
Set up the environment
Before you can proceed with creating a new Erlang project in IntelliJ IDEA, you need a few things installed and configured in your environment.
Install and enable Erlang plugin
Press Control+Alt+S to open the IDE settings and then select
.Switch to the Marketplace tab at the top and search for a plugin called Erlang.
Once the plugin is found, click Install, apply the changes, and close the dialog. Restart the IDE if prompted.
Once the plugin is installed and enabled, the following Erlang-specific settings and configurations become available in IntelliJ IDEA:
Main menu:
Control+Alt+S
Control+Alt+S
Control+Alt+S
Control+Alt+S
Control+Alt+S
Control+Alt+S
Control+Alt+S
Install Erlang/OTP framework
Erlang/OTP is a set of Erlang libraries and design principles essential for development.
To install Erlang/OTP, follow the instructions that correspond to your OS:
Download the Erlang/OTP package and run the installation wizard. Take a note of the installation folder path.
Once the installation is over, add the <Erlang installation folder>\bin path to the PATH environment variable:
To verify that Erlang/OTP is installed correctly, type
erl
in the command prompt to make sure the Erlang shell starts up:
Run the following command in the terminal:
brew install erlangsudo port install erlang +sslTo verify that Erlang/OTP is installed correctly, start up the Erlang shell from the terminal using the
erl
command:
Run the following command in the terminal:
Ubuntu/Debian:
sudo apt-get update sudo apt-get install erlangFedora:
sudo yum install erlangFreeBSD:
sudo pkg update sudo pkg install erlangTo verify that Erlang/OTP is installed correctly, start up the Erlang shell from the terminal using the
erl
command:
Install and configure Rebar
In addition to Erlang/OTP, you will also need Rebar3: a build tool that helps compile and test Erlang applications. It is the spiritual successor to rebar (v2.x), which is now deprecated.
Rebar3 comes in the form of a portable executable escript file which can be used either as is (the script version) or as a means to install a faster, fully compiled form of Rebar3.
The latest stable release of the escript can be downloaded from within IntelliJ IDEA:
Press Control+Alt+S to open the IDE settings and then select
.Click Download the latest Rebar 3.
Select the directory where you want the downloaded escript to be saved.
The Path and Version fields will be automatically populated with the corresponding information.
The escript is also available for downloading on the official Rebar3 website.
The process of installing Rebar3 from source, as well as other ways to install and run it are described at length in the tool's official documentation.
Configure the IDE to work with Erlang SDK
The last step of the initial configuration is to let IntelliJ IDEA know where the Erlang SDK is located on your computer.
Once your project is opened, go to the
dialog Control+Alt+Shift+S.In the
section, click to add a new SDK, then select .In the file chooser dialog that appears, select the directory where you installed Erlang/OTP, for example C:\Program Files (x86)\erl23.3.
The SDK will be detected and displayed on the list of available SDKs, its lib folder automatically added to the classpath.
If you don’t know where Erlang OTP was installed, check the following directories:
OS
Path
Windows
C:\Program Files (x86)\erl<version>
Linux
/usr/lib/erlang/<version>
macOS: MacPorts
/opt/local/lib/erlang/<version>
macOS: Homebrew
/usr/local/Cellar/erlang/<version>
Create a new Erlang project
You can create a new Erlang project in IntelliJ IDEA in one of two ways:
Use the New Project wizard to create a bare-bones Erlang OTP project with minimal structure.
Generate the project's structure from a Rebar3 template using the Terminal tool window.
Use the New Project wizard
Go to
.In the dialog that appears, choose
as the project's base.Ignore the additional frameworks at this point and click
.In the dialog that appears, choose
Ignore additional frameworks at this point and click as the project's base. .In this step, installed and configured. If you have several versions of the SDK installed, choose the one that you need from the list, then click .
will be pre-selected as the project's SDK - as long as Erlang/OTP framework has beenGive your project a name and choose where to save it. Click
to close the dialog.
Generate a new project with Rebar3
Make sure that Rebar3 is installed and added to system PATH.
Open the Terminal tool window Alt+F12.
Enter the following command:
rebar3 new app myAwesomeProject
This will generate a new project called myAwesomeProject in the current directory from the built-in Rebar3 template called app.
Once generated, the project needs to be imported into the IDE so that you can work with it. For more information, refer to the next section.
Import existing Erlang project
If you already have an Erlang project, you can follow the steps from this guide to import it into IntelliJ IDEA.
Erlang project structure
Once your project is imported into IntelliJ IDEA, you can see its structure as a tree in the Project tool window Alt+1. For instance, it will look like this for myAwesomeProject created earlier with Rebar:
In addition to standard files and folders generated by Rebar, IntelliJ IDEA creates a folder called .idea and a file called <yourProjectName>.iml. They contain various settings, such as module structure, VCS mappings, code style settings, and so on, that reflect the configuration of your project from the IDE's perspective.
You will also see your Erlang SDK added to the list of External Libraries. Its contents can be browsed directly from the Project tool window.
Erlang facets
Each Erlang module in your project is supplied with a dedicated Erlang facet. You can use facets to pass parse_transform
compiler directives to modules.
Apply parse transformations using Erlang facet
Once your project is opened, go to the
dialog Control+Alt+Shift+S.In the
section, select the Erlang facet that corresponds to the module to which you want to apply parse transforms.Populate the
field that appears on the right with a compiler directive. The format is as follows:-compile({parse_transform, moduleName}).