Custom Dep Resources
Resources Compatible with versions 3.7.0 and Above
Starting with version 3.7.0, Rebar3 published a new API for custom resources, which gives access to the project’s local configuration to enable more powerful custom dependency formats. They can use contextual information from the current build to customize how dependencies might be fetched.
🚧
The new Interface is not backwards compatible
This new interface is unknown and unsupported in versions prior to 3.7.0. If you are writing libraries that should work with all Rebar3 copies, skip to the next section, where resources compatible with all Rebar3 versions are documented. Old interfaces however are still compatible with all versions and no support for existing project has been broken in adding the new API.
The new callback API is defined as follows:
The callbacks allow the resource plugin to have access to the rebar_state:t()
data structure, which lets you access and manipulate the Rebar3 state, find application state, and generally work with the rebar_state
, rebar_app_info
, rebar_dir
, and the new rebar_paths
modules.
An example of a plugin making use of this functionality is rebar3_path_deps. Rebar3’s own hex package resource uses this API.
A resource plugin is initialized the same way as any other plugin would:
Where Tag
stands for the type in the deps
configuration value (git
, hg
, etc.), and Module
is the callback module.
The callback module may look as follows:
Resources Compatible with all versions
Prior to version 3.7.0, the dependency resource framework was a bit more restricted. It had to essentially work context-free, with only the deps
information from the rebar.config
and rebar.lock
to work from. It was not possible to have any information relative to the project configuration, which essentially restricted what could be done by each resource.
These custom resources are still supported in Rebar3 versions higher than 3.7.0, and so if you have users running older build, we recommend that you develop this kind of resources only.
Each dependency resource must implement the rebar_resource
behaviour.
Included with rebar3
are rebar_git_resource, rebar_hg_resource and rebar_pkg_resource.
A custom resource can be included the same way as a plugin. An example of this can be seen in Kelly McLaughlin’s rebar3_tidy_deps resource:
This resource rebar_github_resource
which implements the rebar3
resource behaviour is added to the list of resources available in rebar_state
. Adding the repo as a plugin to rebar.config
allows this resource to be used:
Writing a Plugin working with both versions
If you want to write a custom resource plugin that works with both versions, you can dynamically detect arguments to provide backwards-compatible functionality. In the example below, the new API disregards all new information and just plugs itself back in the old API:
Note that if you resource really needs the new API to work, backwards compatibility will be difficult to achieve since whenever it will be called, it won’t have all the information of the new API.
This approach is mostly useful when you can provide an acceptable (even if degraded) user experience with the old API.