Commands

View Source

Usage of each Rebar3 command.

Each command represents a task which runs one or more providers to fulfill the task.

alias

List aliases' definitions (from rebar.config).

Example output:

test=eunit,ct --suite=rebar_alias_SUITE,cover
check=xref,dialyzer

as

Higher order task which takes a profile name and list of tasks to run under that profile.

compile

After ensuring all dependencies are available, and fetching them if they are not, compile will compile the needed dependencies and the project's apps' .app.src and .erl files.

OptionTypeDescription
-d/--deps_onlynoneOnly compile dependencies, no project apps will be built

completion

Since version 3.23.0

Generates a completion file for one of the supported shells: bash, zsh.

Completion files can be generated based on the project setup, so autocompletion also works for all plugins used in the project, not just for default providers.

To use generated completion files run source path/to/generated/file.

OptionTypeDescription
-a/--aliasesComma separated list of stringsOS level aliases on which rebar3 completion will be triggered (e.g. "rebar, r3")
-f/--filestringCompletion file name. If not absolute, it's relative to the _build/<profile>/ directory
-s/--shellatomSpecify type of the completion file. By default it is autodected using $SHELL variable. Valid values are bash and zsh.

zsh specific requirement

Make sure that autoload -Uz compinit; compinit is called in .zshrc file.

For better user experience, set default autocompletion and override it when needed. Default autocompletion can be set by generating a global completion file and loading it in .bashrc or .zshrc.

To generate a global (project-independent) completion file run rebar3 completion --file path/to/global/completion/file outside a rebar3 project.

clean

Removes compiled BEAM files from apps.

The clean command by default removes the BEAM files for top-level applications. It does so while respecting profiles, which means that 'rebar3 clean' will only clean the default profile, and 'rebar3 as test clean' will only clean the test profile.

OptionTypeDescription
--all/-anoneClean all apps, including the dependencies
--appsComma separated list of stringsClean a specific list of apps or dependencies
--profile/-pstringSpecify a profile (alternative to rebar3 as clean)

ct

Runs common tests for the project located under the test/ directory.

Most Common Test options as described in the Erlang documentation for ct_run are available. Some common ones are described below:

OptionTypeDescription
--dirComma separated list of stringsCompile and run all test suites in the specified directories.
--suiteComma separated list of stringsCompile and run all test suites specified. Must be specified by full path, either absolute or relative to the current directory.
--groupComma separated list of stringsTest groups to run. See the Common Test Documentation.
--caseComma separated list of stringsList of test cases to run. See the Common Test Documentation.
--specComma separated list of stringsList of Test Specifications
--join_specsComma separated list of stringsLike --spec but merges all the specifications into one and does a single run.
--repeatIntegerHow often to repeat the tests
--durationString (format: HHMMSS)Max allowed duration of the test run
--untilString (format: HHMMSS)Time until which to run the tests
--force_stoptrue | false | skip_restForce termination on test timeout
--multiply_timetrapsIntegerExtends the timeout values for tests by a given multiplier value
--scale_timetrapsBooleanEnables automatic timeout value scaling, when using code coverage or tracing
--abort_if_missing_suitesBooleanAbort the test run if a test suite is missing (Default: true)
--sys_configStringList of OTP application config files (like sys.config) that should be applied by Rebar3 before the test run.
--configComma separated list of stringsConfig files to use when running tests. See the Common Test Documentation.
--allow_user_termsBooleanAllow user defined config values in config files. See the Common Test Documentation.
--decrypt_keyStringIf the configuration file is encrypted, set the key to decrypt it
--decrypt_fileStringIf the configuration file is encrypted, point to the file containing the key to decrypt it
--logdirStringThe directory in which test logs will be written. See the Common Test Documentation. Default: _build/test/logs
--logoptsComma separated list of stringsSet common test logging options. See the Common Test Documentation. Default: _build/test/logs
--readableBooleanAdds test names with results on a per-test basis, and only displays common-test logs in the terminal on failing tests. Default: true
--verbose, -vBooleanEnable verbose output. Default: false
--verbosityIntegerSet the level of Common Test verbosity
--cover, -cBooleanGenerate cover data
--cover_export_nameStringChange the name of the code coverage file
--labelStringSet a test label
--basic_htmlBooleanshow basic HTML
--stylesheetStringCSS stylesheet to apply to HTML output
--create_priv_dirauto_per_run | auto_per_tc | manual_per_tcchange the behaviour of the private (scratch) directories creation done by Common Test
--includeStringAdditional directories containing include files. Option added for parity with ct_run, usually rebar3 should take care of include file paths
--name, --snameStringStart a distributed node with a given name
--setcookieStringSet a value for the distributed cookie
--compile_onlyBooleanCompile the project with the test configuration specified, but without running the tests

Runs in the test profile.

cover

Performs coverage analysis on modules called by Common Test or Eunit test suites. Call as rebar3 do ct, cover, rebar3 do eunit, cover or the combination of both with rebar3 do eunit, ct, cover while the {cover_enabled, true} option is in your rebar config file, or if the cover flags were used with these commands individually.

An HTML report is generated.

OptionTypeDescription
-m, --min_coverageIntegerMandate a coverage percentage required to succeed (0..100)
--reset, -rnoneResets all cover data
--verbose, -vnonePrints coverage analysis in the terminal.

Specific modules can be blacklisted from code coverage by adding {cover_excl_mods, [Modules]} to the config file. Specific applications can be blacklisted by adding {cover_excl_apps, [AppNames]} to the config file.

deps

Lists dependencies, whether they're source or package dependencies, and whether they're locked or not. Those that are locked but not matching the lock file are followed by an asterisk (*).

do

Higher order provider for running multiple tasks in a sequence, separated by commas. Example: rebar3 do a, b, c.

dialyzer

Builds and keeps up-to-date a suitable PLT (Persistent Lookup Table), and uses it to carry out success typing analysis on the current project.

OptionTypeDescriptionDefault
--incremental, -ibooleanEnable incremental analysis mode.false
--update-plt, -ubooleanEnable updating the PLT.true
--succ-typings, -sbooleanEnable success typing analysis.true

For instructions on suppressing warnings read the Requesting or Suppressing Warnings in Source Files section of the Dialyzer documentation.

PLT files are named <prefix>_<otp_release>_plt; The base PLT is a PLT containing the core applications often required for a project's PLT. One base PLT is created per OTP version and stored in base_plt_location. A base PLT is then used to build project PLTs.

The following (optional) configurations can be added to a proplist of options dialyzer in rebar.config:

OptionDescription
warningsa list of dialyzer warnings
get_warningsdisplay warnings when altering a PLT file (boolean)
plt_appsthe strategy for determining the applications which are included in the PLT file, top_level_deps to include just the direct dependencies or all_deps to include all nested dependencies (the direct dependent applications are listed in applications and included_applications of their .app files.)
plt_extra_appsa list of applications to include in the PLT file (the applications in base_plt_apps will already be in the list)
plt_locationthe location of the PLT file, local to store in the profile's base directory (default) or a custom directory.
plt_prefixthe prefix to the PLT file, defaults to "rebar3"
base_plt_appsa list of applications to include in the base PLT file
base_plt_locationthe location of base PLT file, global to store in $HOME/.cache/rebar3 (default) or a custom directory
base_plt_prefixthe prefix to the base PLT file, defaults to "rebar3"
incrementalincremental analysis mode

edoc

Generates documentation using doc.

Runs in the docs profile.

escriptize

Generates an escript executable containing the project's and its dependencies' BEAM files.

Config OptionTypeDescription
escript_main_appatomName of the application to turn to an escript. Defaults to the top-level app if there is only one. When using an umbrella repository (with multiple top-level apps), this value must be specified.
escript_namestringName of the generated escript, and default module name to boot (Module:main(_)). Defaults to the value for escript_main_app
escript_incl_appslist of atomsList of applications to include in the escript archive aside from the main app and its dependencies (from the app file). Defaults to []
escript_emu_argsstringEscript emulator arguments (after %%! in escript declarations). The string must begin with %%! and end with a line break. An example string would be "%%! +sbtu +A0\n". The Default value is "%%! -escript main MainApp\n"
escript_shebangstringLocation of escript file to run. Defaults to "#!/usr/bin/env escript\n". The end of line marker must be included in the string.
escript_commentstringArbitrary comment to put into the generated escript. Must include a newline marker at the end. Defaults to %%\n.

To override the default module name for the escript (which is expected to be the same as the escript_name), add -escript main Module to escript_emu_args.

Example escript configuration from relx:

{escript_emu_args, "%%! +sbtu +A0 -noinput\n"}.
{escript_incl_apps, [getopt, erlware_commons, bbmustache, providers, relx]}.

eunit

Runs EUnit tests on project apps.

Config OptionTypeDescription
--applicationComma separated list of stringsApplication test suites to run. Equivalent to [{application, App}]
-c, --coverBooleanGenerate cover data. Defaults to false
--cover_export_nameStringBase name of the coverdata file to write
-p, --profileBooleanShow the slowest tests. Defaults to false
-d, --dirComma separated list of stringsDirs to load tests from. Equivalent to [{dir, Dir}]
-f, --fileComma separated list of stringsFiles to load tests from. Equivalent to [{file, File}]
-m, --moduleComma separated list of stringsModules to load tests from. Equivalent to [{module, Module}]
-t, --testComma separated list of stringsTests to run. The format is Module:Func1+Func2. Equivalent to [{test, Module, Function}]
-g, --generatorComma separated list of stringsGenerators to load tests from. The format is Module:Func1+Func2. Equivalent to [{generator, Module, Function}].
-v, --verboseBooleanVerbose output. Defaults to false.
--nameStringGives a long name to the node
--snameStringGives a short name to the node
--sys_configComma separated list of stringsList of application config files
--setcookieStringSets the cookie if the node is distributed

For more details, see EUnit.

Runs in the test profile.

get-deps

Not Required

Unlike Rebar 2 this command is not required for fetching dependencies. The compile command will result in dependencies being fetched and then built if they aren't already. This command is useful if you have a specific use case that requires fetching dependencies separate from compilation.

Fetch project dependencies.

help

Displays a list of tasks or help for a given task or subtask.

OptionDescription
<task>Task to print help for.
<namespace> <task>Task within \<namespace> to print help for

new

Creates a new project from templates. See a list of available templates by providing no arguments.

OptionDescription
--force, -fOverwrite existing files.
help <template>Display all variables and arguments for each template

path

Print paths to build dirs in current profile.

OptionTypeDescription
--appComma separated list of stringsComma separated list of applications to return paths for.
--basenoneReturn the base path of the current profile.
--binnoneReturn the bin path of the current profile.
--ebinnoneReturn all ebin paths of the current profile's applications.
--libnoneReturn the lib path of the current profile.
--privnoneReturn the priv path of the current profile.
--separator, -sstringIn case of multiple return paths, the separator character to use to join them.
--srcnoneReturn the src path of the current profile's applications.
--relnoneReturn the rel path of the current profile.

release

Builds release of project. Call rebar3 help release for arguments.

relup

Creates a relup from two releases that were already built by calling rebar3 release without clearing the _build directory. Call rebar3 help relup for arguments.

report

Generates contextual data to include in bug reports.

shell

Runs a shell with project apps and deps in path. Intended for development use only; use Releases for production.

OptionTypeDescription
--configstringAllows to load a config file, if any. Defaults to the sys_config entry defined for relx if present.
--name, --snameatomStarts the node in network mode. Equivalent to erl's -name and -sname options.
--setcookiestringSets the cookie for a distributed node. Equivalent to erl's -setcookie option.
--scriptstringpath to an escript to be evaluated before applications are started.
--appsstringComma-separated list of application names to be booted. Defaults to the apps in the relx release if present.
--start-cleanWhen specified, no apps are booted by the shell; useful to override release or shell tuple configurations in rebar.config.
--relname, -ratomIf multiple releases are present, specify which one to pick.
--relvsn, -vstringIf multiple releases are present, specify which version to use.
--env-filestringPath to file of os environment variables to setup before expanding vars in config files.
--user_drv_argsstringFor versions of Erlang prior to 26, this option can be used to pass arguments to the user_drv start function for creating custom shells. Starting with Erlang 26, the arguments defined with this option are applied to the shell start_interactive function.
--evalstringErlang expressions to execute during startup. These will run last, just before presenting the user with the Erlang shell prompt. There can be more than one --eval switch. Roughly equivalent to erl's -eval option.

The shell booted with this command has a running agent that allows running Rebar3 commands dynamically, such as r3:compile() or r3:upgrade(), and have new modules automatically reloaded. Specific namespaces can be reached by calling r3:do(Namespace, Command). No arguments can be passed to these commands.

tar

Builds a compressed tar archive of release built of project. Call rebar3 help tar for arguments.

tree

Prints a tree of dependencies and transitive dependencies of the project.

OptionTypeDescription
-v, --verbosenonePrint repo and branch/tag/ref for git and hg deps

lock

Get unbuilt dependencies to be added to the rebar.lock file. They will just have been downloaded, but none of their build script should have run. Though this is not necessarily true with pre/post hooks and dep plugins.

unlock

Unlocks dependencies. Specify a comma separated list of dependencies to unlock and regenerate the rebar.lock file, or -a,--all to unlock them all and remove the rebar.lock file.

This command should be used when one or more dependencies have been taken out of rebar.config, but remain in the lock file.

OptionTypeDescription
<dependency>stringDependencies to unlock (comma-separated).
-a, --allnoneUnlock all dependencies.

update

Updates the package index.

upgrade

Takes the current dependency specifications in rebar.config and fetches the most up-to-date versions satisfying them, while updating the lock file accordingly.

OptionTypeDescription
<dependency>stringDependencies to upgrade (comma-separated).
-a, --allnoneUpgrade all dependencies.

version

Prints version for rebar3 and current Erlang.

xref

Runs cross reference analysis.