rebar3 引用本地elixir 模块

发布时间 2023-12-27 09:57:25作者: 荣锋亮

前边简单说过基于rebar_mix 使用elixir模块,但是使用的模块是三方的,如果时候我们可以需要使用自己的
就可以使用本地git 项目,或者搭建自己的私服git,以下是一个简单使用

项目准备

  • 本地elixir mix 项目
    一个基于mix cli 创建的项目,同时进行git init
 
mix new login 

git init
git add  --all
git commit -m 'init'
  • rebar3 项目使用本地elixir 模块
    rebar.config
 
{erl_opts, [debug_info]}.
{deps, [
  % 添加引用
  {decimal, "2.0.0"},
  % 使用git 本地项目
  {login,  {git, "file:///Users/dalong/mylearning/elixir-learning/modules/login", {branch, "main"}}}
]}.
 
{shell, [
    {apps, [basic]}
]}.
 
{plugins, [rebar_mix]}.
 
{provider_hooks, [{post, [{compile, {mix, consolidate_protocols}}]}]}.
  • 代码调用
    src/basic_login.erl
 
-module(basic_login).
-export([init/0]).
init() ->
    'Elixir.Login':hello().

测试

  • 初始化依赖
rebar3  get-deps
  • 测试
rebar3 shell

效果

说明

rebar3 对于本地模块的引用不如elixir mix 那样方便,但是基于git 是一个不错的选择,同时也可以保障代码的持续演进

参考资料

https://hexdocs.pm/mix/1.16.0/Mix.html
https://rebar3.org/docs/configuration/dependencies/
https://rebar3.org/docs/configuration/plugins/#elixir-dependencies
https://github.com/tsloughter/rebar_mix
https://github.com/barrel-db/rebar3_elixir_compile
https://rebar3.org/docs/configuration/configuration/#hooks