在一个Erlang应用里, 有可能会有对其他应用的依赖, 我们可以把这个依赖定义在rebar.config 文件中. 但是如果依赖的应用不符合rebar app的要求的结构, 编译的时候就会报这个错误("Dependency failure : Application jsonx not found at the top level of directory ...").
导致错误的原因包括但不限于
Cause 1 --> this is the error message given when someone adds a dependency that is not of the structure <appname>/src but instead like <appname>/apps/<something>/src or anything else.
Cause 2 --> This error also occurs, when the src/.app file isn't in the format src/.app.src.
那么如何fix这个错误呢, 如果依赖于一些Erlang程序库, 但是这些程序库不符合rebar 对结构的要求, 我们可以在设置依赖的时候填上Raw标签.
基本上有两个步骤
Step 1) 修改应用的配置文件rebar.config, 加入以下几行. 这个用于加载一个plugin, 该plugin可以帮助处理raw的依赖库.
{plugins, [
{rebar_raw_resource,
{git, "git://github.com/basho/rebar_raw_resource.git",
{branch, "master"}}}
]}.
Step 2) 修改依赖库的配置文件rebar.config, 加入raw 标签
{deps, [
. . .
{mydep1, {raw, {mydep1-resource-specification} }},
{mydep2, {raw, {mydep2-resource-specification}, [raw-options] }},
. . .
]}.
比如原来是这样,假设jsonx库不符合rebar应用结构
{erl_opts, [debug_info]}.
{deps,
[
{emqttc, {git, "https://github.com/emqtt/emqttc"}},
{gen_tracker, {git, "https://github.com/erlyvideo/gen_tracker.git"}},
{iso8601, {git, "https://github.com/erlsci/iso8601.git", {tag, "1.2.2"}}},
{jsonx, {git, "https://github.com/lukyanov/jsonx.git"}},
]}.
我们为jsonx加入 raw标签后是这样,就是在原来的基础上wrap一个raw 标签
{erl_opts, [debug_info]}.
{deps,
[
{emqttc, {git, "https://github.com/emqtt/emqttc"}},
{gen_tracker, {git, "https://github.com/erlyvideo/gen_tracker.git"}},
{iso8601, {git, "https://github.com/erlsci/iso8601.git", {tag, "1.2.2"}}},
{jsonx, {raw, {git, "https://github.com/lukyanov/jsonx.git"}}},
]}.
这两个步骤以后就可以运行rebar3 来编译了, rebar3会先把插件rebar_raw_resource下载下来,然后用这个插件来帮忙处理RAW依赖库.
##博客仅作个人记录##