Managing non-OTP deps in rebar3

How do you manage dependencies that are not an OTP application/library? How do you upgrade them and distribute them alongside the application?

That could be GraphQL schema, XML schema, some static web content, i18n data, etc.

Currently, I’m using submodules and it works, but it’s inconvenient something (e.g. you can’t anchor it to some specific git tag).

What I’d like to do in rebar.config is something like:

{custom_deps, 
   [{dep_x, {git, Link, {tag, "0.1.0"}}}]}.

and would like that dependency to be stored in priv folder of the applications. Any ideas?

We use git submodules for things like API specifications which are dropped into priv.
EG

[submodule "priv/apis"]
branch = main
path = priv/apis
url = git@github.com:OrgName/apis

and then add a pre hook to update modules before rebar compiles if you want them auto-updated

{pre_hooks, [
{"(linux|darwin|solaris|freebsd)", compile, "git submodule update --recursive --remote"}
]}.

We use almost exactly the same stuff, but we have update profile to trigger submodule update pre-compilation because otherwise update is triggered even when the app is compiled as a dependency.

That would work perfectly if you could anchor a submodule to a specific tag… Otherwise you need to have tag-like branches, which I’d like to avoid :smiley:

Well that sent me down a rabbit hole.

Found something that may make this work with tags

[submodule "priv/apis"]
    branch = main
    path = priv/apis
    url = git@github.com:OrgName/apis
    tag = 0.1.0

and then use in the pre-hook

{pre_hooks, [
  {"(linux|darwin|solaris|freebsd)", compile, "git submodule update --recursive --remote"},
  {"(linux|darwin|solaris|freebsd)", compile, "git submodule foreach 'git checkout $(git config -f $toplevel/.gitmodules submodule.$name.tag)'"}
]}.

This would automatically check out the specified tag in .gitmodules for each submodule and you could just commit the change to link it to the specific ref and leave out the submodule update pre-hook

1 Like