This is pretty creative, I think it might be possible to work something along these lines, like reading back the AST of the module that used Application.compile_env!/2 and if the compile_env func cached the wrong envvar, force a recompile by doing mix compile --force.
Yea but I would like it to autodetect when to execute a force recompile, so only if certain ENVVARS changed from the last time it got compiled.
defp app_changed?(properties, mods, compile_env) do
Keyword.get(properties, :modules, ) != mods or
Keyword.get(properties, :compile_env, ) != compile_env
You can probably use this in conjunction with runtime configuration like in config/runtime.exs introduced as in Elixir 1.11, see Elixir v1.11 released - The Elixir programming language so stuff System.get_env(name) in config/runtime.exs and use Application.compile_env/3 to get it.