Application configuration files

I’ve been trying to get application configuration files working (config/app.config) working and can’t work out what’s going on. If I’m understanding the way the rebar3.config file works correctly I should be able to add a line {config, "./config/app.config"}. and have it load. If I have syntax error in the config file I don’t get an error, and in any case I can’t get application:get_env to return anything in the config file. I also don’t get anything back if I fix the syntax error.

I’ve also tried to put the config file reference in {profiles, [deafult, but again, it doesn’t seem to do anything.

Should this work, or am I totally misunderstanding how these features work?

1 Like

I try these code in docker

docker -it --rm erlang:26 /bin/bash
rebar3 new release myrel
cd myrel
echo "[{myrel, [{a,a}]}]." > config/sys.config
rebar3 shell
...
1> application:get_all_env(myrel).
[{a,a}]

If I understood it right, you want configuration to be loaded when you run rebar3 shell. If that is the case you need to put:

{shell, [
    {config, "config/app.config"},
]}.

in your rebar.config instead of just config tuple.

1 Like

Thanks. There the config does work, but it doesn’t work if I put the config tuple anywhere else (in profiles or in the root of the rebar3.config file).

How can I load it for eunit tests?

Indeed, it works only for shell. For eunit provider, you have to specify separately, in eunit_opts look here . Similarly, you specify it in ct_opts for common test link.

1 Like