Erlang dependency management

published: 2011-01-17

Since software engineering to a large extent is about integration and interaction between different parts of code and solutions, there is very often the issue of managing these as dependencies between parts of a system. They must be loaded into the path of a dependent project or packaged up into a common release, when the time comes.

So when there is help offered for managing these tasks, it makes me all warm and cozy inside.

Erlang, meet Maven

The Maven Erlang Plug-In that I have been part of developing, is actually built with the purpose to solve just these things. Of course it also helps out with other build stuff, much in the same way that Rebar does - you get compilation, dialyzing, testing and reporting. You should try them both out and see what fits you and your project.

If you choose to use the Maven Erlang Plug-In, dependencies and packaging works just as you would expect any other Maven project to do. It is easy and since it builds on the infrastructure of Maven, you can benefit from the architecture that you may already have - repositories, proxies, caches and even continuos integration servers!

Baking an Erlang dependency

I have prepared a small example project to show you both the dependency project, and how to pack it, as well as the dependent project, and how it makes use of the built dependency.

The full source code is available for both projects at:

We will start by cloning out the MochiWeb dependency project and looking at the POM file. It is setup to use out plug-in but and defines the project to be use the packaging erlang-otp.


> git clone git://github.com/olle/mochiweb.git
> cd mochiweb
> cat pom.xml
<project 
    xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
      http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mochimedia</groupId>
  <artifactId>mochiweb</artifactId>
  <version>1.5.0</version>
  <packaging>erlang-otp</packaging>
  <name>MochiWeb</name>
  <build>
    <plugins>
      <plugin>
        <groupId>eu.lindenbaum</groupId>
        <artifactId>maven-erlang-plugin</artifactId>
        <version>2.0.0-SNAPSHOT</version>
        <extensions>true</extensions>
      </plugin>
    </plugins>
  </build>
</project>

Please note that I am using the 2.0.0-SNAPSHOT version of our plug-in, and that it is still a work in progress.

The idea in the Maven Erlang Plug-In is convention over configuration so we do not have to configure anything as long as the project is setup with the default folder structure.

  • src/main/erlang/ - main .erl code
  • src/main/include/ - .hrl includes
  • src/main/priv/ - other resources for the main code
  • src/test/erlang/ - tests
  • src/test/priv/ - other resources for testing

The folder structure is standard to the erlang-otp packaging type. You can read more about it in the plug-in introduction. Now we can simply package and install the project dependency, just like any other Maven project.


> mvn install
> ll target/
total 240
 68B 17 Jan 22:33 lib/
170B 17 Jan 22:33 mochiweb-1.5.0/
136B 17 Jan 22:33 mochiweb-1.5.0-test/
117K 17 Jan 22:35 mochiweb-1.5.0.tar.gz
714B 17 Jan 22:34 surefire-reports/

Great! Our Erlang/OTP artifact is built, packaged as a tar.gz and installed into your local Maven cache (you should be able to see the log line starting with Installing...). Let us clone out the dependent project and see how it is configured.


> git clone git://github.com/olle/mochigo.git
> cd mochigo
> cat pom.xml
<project
    xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
      http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.studiomediatech</groupId>
  <artifactId>mochigo</artifactId>
  <version>1.0</version>
  <packaging>erlang-otp</packaging>
  <name>MochiGo</name>
  <build>
    <plugins>
      <plugin>
        <groupId>eu.lindenbaum</groupId>
        <artifactId>maven-erlang-plugin</artifactId>
        <version>2.0.0-SNAPSHOT</version>
        <extensions>true</extensions>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>com.mochimedia</groupId>
      <artifactId>mochiweb</artifactId>
      <version>1.5.0</version>
      <type>erlang-otp</type>
    </dependency>
  </dependencies>
</project>

We have added the dependency to the dependencies configuration in our project and added the type as erlang-otp. The Maven Erlang Plug-In will resolve the dependency and make it available locally so that we can compile and run our project.


> mvn package
> ll target/
total 8
102B 13 Jan 00:19 lib/
136B 17 Jan 23:04 mochigo-1.0/
102B 17 Jan 23:04 mochigo-1.0-test/
1,2K 17 Jan 23:04 mochigo-1.0.tar.gz
> ll target/lib/
total 0
170B 13 Jan 00:19 mochiweb-1.5.0/

The MochiWeb artifact is extracted into the target/lib/ folder. As a bonus we can run the project with the dependency added to the Erlang path by simply issuing:


> mvn erlang:run
...
[INFO] Successfully loaded 34 .beam file(s) into backend node.
[INFO] Application started successfully on backend node.
[INFO] Press [ENTER] to stop the application and cleanup the backend node.

To see the application, and the embedded MochiWeb server, in action browse to http://localhost:8888 - but more about that in another article. Good luck!

blog comments powered by Disqus
Olle Törnström

Status: I'm currently moving on to new challanges; focusing on web engineering and development for people with devices that have browsers. Yay!

Absolutely not news: