Dependency management (rebar 依赖库配置)

本文介绍如何使用Rebar进行依赖管理,包括定义依赖项、从不同的源获取依赖项的方法及raw依赖项的概念。通过配置文件rebar.config,可以递归地获取并构建项目的所有依赖项。

Dependency management

Rebar can fetch and build projects including source code from external sources(git, hg, etc.)

It is assumed that these dependencies are available in source form and adhere to the rebar conventions. Moreover, if a project's dependencies have their own dependencies, rabar fetches and builds these transitive dependencies recursively(递归的).

Defining dependencies


Dependencies are defined in the rebar.config file by the adding the deps tuple of the following form: {deps, [Dependency1, Dependency2, ...]}. Each dependency is defined by a triplet {App, VsnRegex, Source} where:

  • 'App' specifies the OTP application name, either as an atom or a string
  • 'VsnRegex' is a string containing a regular expression that must match the OTP application version string
  • 'Source' specifies the engine used to fetch the dependency along with an engine specific location :
    • {hg, Url, Rev} Fetch from mercury repository
    • {git , Url} Fetch from git repository
    • {git, Url, {branch, Branch}} Fetch from git repository
    • {git, Url, ""} == {git, Url, {branch, "HEAD"}} Fetch from git repository
    • {git ,Url, {tag, Tag}} Fetch from git repository
    • {git, Url, Rev} Fetch from git repository
    • {bzr, Url, Rev} Fetch from a bazaar repository

"Raw" dependencies

A dependency specification can have an optional fourth element: [raw].

Such dependencies are called "raw' and rebar does not require them to have a standard Erlang/OTP layout which assumes the presence of either src/dependency_name.app.src or ebin/dependency_name.app files.

"Raw" dependencies can still contain rebar.config and even can have the proper OTP directory layout, but they won't be compiled.

Only a subset of rebar commands will be executed on the "raw' subdirectories: get-deps, update-deps, check-deps, list-deps and delete-deps.

Example

in rebar.config

{deps, [
  {em, ".*", {git, "https://github.com/sheyll/erlymock.git"}},
  {nano_trace, ".*", {git, "https://github.com/sheyll/nano_trace.git", {branch, "feature/rebar-migration"}}},
  {mochiweb, "2.3.2", {git, "https://github.com/mochi/mochiweb.git", {tag, "v2.3.2"}}},
  % Or specify a revision to refer a particular commit, useful if the project has only the master branch
  % {mochiweb, "2.3.2", {git, "https://github.com/mochi/mochiweb.git", "15bc558d8222b011e2588efbd86c01d68ad73e60"},
  % An example of a "raw" dependency:
  {rebar, ".*", {git, "git://github.com/rebar/rebar.git", {branch, "master"}}, [raw]}
 ]}.

原文链接: https://github.com/rebar/rebar/wiki/Dependency-management

转载于:https://my.oschina.net/lvhuizhenblog/blog/1925277

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值