Building Projects with rebar3
rebar.lock pins dependency versions — commit it for applications.
21.1 Creating projects
rebar3 new app myapp # OTP application
rebar3 new lib mylib # library (no supervision tree)
rebar3 new release myrel # release with apps/ directory
rebar3 new escript mytool
rebar3 new umbrella myumbrella21.2 Project layout
myapp/
├── rebar.config
├── src/
│ ├── myapp.app.src # application resource file
│ ├── myapp_app.erl # application callback
│ ├── myapp_sup.erl # top supervisor
│ └── myapp_server.erl
├── include/ # .hrl headers
├── priv/ # non-code assets
├── test/ # EUnit / Common Test suites
└── config/
├── sys.config
└── vm.args21.3 rebar.config
{erl_opts, [debug_info, warnings_as_errors, warn_missing_spec]}.
{deps, [
{cowboy, "2.12.0"},
{jsx, "~> 3.1"},
{mylib, {git, "https://github.com/me/mylib.git", {tag, "v1.0.0"}}}
]}.
{shell, [{config, "config/sys.config"}, {apps, [myapp]}]}.
{relx, [
{release, {myapp, "0.1.0"}, [myapp, sasl]},
{mode, dev},
{sys_config, "config/sys.config"},
{vm_args, "config/vm.args"}
]}.
{profiles, [
{prod, [{relx, [{mode, prod}]}]},
{test, [{deps, [proper, meck]}]}
]}.
{plugins, [rebar3_hex, rebar3_format, rebar3_lint]}.
{project_plugins, [erlfmt]}.
{dialyzer, [{warnings, [unmatched_returns, error_handling]}]}.21.4 Common commands
rebar.lock pins dependency versions — commit it for applications.
rebar3 compile
rebar3 shell # REPL with project loaded (and apps started)
rebar3 eunit / rebar3 ct / rebar3 proper
rebar3 cover # coverage report
rebar3 dialyzer
rebar3 xref # cross-reference checks (undefined calls)
rebar3 edoc / rebar3 ex_doc
rebar3 release / rebar3 as prod tar
rebar3 tree / rebar3 upgrade --all / rebar3 unlock
rebar3 hex publish
rebar3 fmt # erlfmt plugin21.5 Erlang.mk & Mix
Alternatives: erlang.mk (Makefile-based, used by Cowboy/RabbitMQ) and Elixir's Mix (can build Erlang projects too).