Rebar3 builds
New project
Rebar3 is the standard build tool. The new command scaffolds a project from a template: app for an OTP application with a supervisor, lib for a plain library, escript for a command line tool.
The name you pass becomes the folder and the application name, and the generator writes the skeleton without asking a single question.
rebar3 new app myapp
===> Writing myapp/src/myapp_app.erl
===> Writing myapp/src/myapp_sup.erl
===> Writing myapp/src/myapp.app.src
===> Writing myapp/rebar.config
===> Writing myapp/.gitignore
===> Writing myapp/LICENSE.md
===> Writing myapp/README.md
Project layout
Source lives in src, build products in _build, and the rebar.config file holds the project settings and dependencies.
The scaffold also writes an OTP application skeleton with an application callback and a supervisor, which lessons 34 to 36 explain. The first build adds rebar.lock, the file that pins dependency versions.
myapp/ ├── rebar.config ├── src/ │ ├── myapp.app.src │ ├── myapp_app.erl │ └── myapp_sup.erl ├── .gitignore ├── LICENSE.md └── README.md
Compile
The compile task builds every module in src and leaves beam files under _build. Rebar3 tracks dependencies and only rebuilds what changed.
Warnings from the compiler appear in the output; treat them as errors until the project is green.
rebar3 compile
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling myapp
Run it
The shell task starts an erl with the project on the code path and boots the application. Your modules are already loaded and ready to call.
For a one-off run without the shell, use the escript template or erl with the -pa flag pointing at the ebin folder.
rebar3 shell
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling myapp
Erlang/OTP 27 [erts-15.2.7.14] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [jit:ns]
===> Booted myapp
Eshell V15.2.7.14 (press Ctrl+G to abort, type help(). for help)
Next: Testing with EUnit
Questions
A new set of questions in a new order every time. Choose one answer for each, then check.
-
Which template builds an OTP application with a supervisor?
Answer
appThe app template writes an application callback and a supervisor; the lib template writes a plain library.
-
What does
rebar3 new app myappcreate?Answer
A project folder named
myappwith a skeletonThe generator writes the folder, the source files, the app resource file and the config.
-
Which folder holds the source of a rebar3 project?
Answer
srcErlang sources live in
src; tests go totestwhen the project has them. -
Where do build products go?
Answer
_buildRebar3 writes beams and generated files under
_build/default/lib/<app>/. -
What is
rebar.configfor?Answer
Project settings and dependencies
The config holds compiler options, plugins and dependency declarations.
-
What describes the application name, version and its dependencies?
Answer
src/myapp.app.srcThe
.app.srcfile becomes the application resource, and it lists the applications the app needs. -
What does
rebar3 compiledo?Answer
Builds every module in
srcunder_buildThe compile task verifies dependencies, analyzes applications and compiles the sources to beams.
-
What does
rebar3 shelldo?Answer
Starts erl with the project on the code path and boots the app
The shell task builds the project, adds its ebin folders to the code path and boots the application.
-
Which file pins dependency versions after the first build?
Answer
rebar.lockrebar.lockrecords the exact versions the build resolved, so the next build gets the same ones. -
Which command starts a new project from a template?
Answer
rebar3 newrebar3 new <template> <name>writes a fresh project skeleton.
The examples on this page were run with Erlang/OTP 27 (erts-15.2.7.14) and rebar3 3.27.3 on Alpine Linux 3.24.3 (x86_64) in a Docker container.
Article author: Arthur Isaev