In my mix.exs
I used to be able to call other Modules in order to fetch some configurations for my application-env
configuration. Somehow this is not possible anymore since a few weeks (or the update to Elixir 1.11 maybe)
Here is an example of calling a module MyApp.Config.application_env()
from inside my mix.exs
file:
./mix.exs
defmodule MyApp.MixProject do
use Mix.Project
def project do
[
app: :my_app
version: "0.2.0",
elixir: "~> 1.5",
elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:phoenix, :gettext] ++ Mix.compilers(),
start_permanent: Mix.env() == :prod,
aliases: aliases(),
deps: deps(),
test_paths: ["test", "lib"]
]
end
def application do
[
mod: {MyApp.Application, []},
extra_applications: [:logger, :runtime_tools],
env: MyApp.Config.application_env()
]
end
# Specifies which paths to compile per environment.
defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]
# deps and aliases ....
./lib/config.ex
defmodule MyApp.Config do
def application_env do
[my_config: "foo", another_config: "bar"]
end
end
Since the update to Elixir 1.11 I cannot call this module anymore since the compiler complains like this:
** (UndefinedFunctionError) function MyApp.Config.application_env/0 is undefined (module MyApp.Config is not available)
MyApp.Config.application_env()
mix.exs:28: MyApp.MixProject.application/0
(mix 1.11.0) lib/mix/tasks/compile.app.ex:382: Mix.Tasks.Compile.App.project_apps/1
(mix 1.11.0) lib/mix/tasks/compile.all.ex:97: Mix.Tasks.Compile.All.load_apps/2
(mix 1.11.0) lib/mix/tasks/compile.all.ex:24: Mix.Tasks.Compile.All.run/1
(mix 1.11.0) lib/mix/task.ex:394: Mix.Task.run_task/3
(mix 1.11.0) lib/mix/tasks/compile.ex:119: Mix.Tasks.Compile.run/1
(mix 1.11.0) lib/mix/task.ex:394: Mix.Task.run_task/3
I tried require
-ing and import
-ing the MyApp.Config
module, but nothing helped. The config.ex
file is compiled and put into the _build/dev/ebin
folder, but somehow it is not available during compile-time. I also tried to set it to an module attribute like this: @config MyApp.Config
, but even this didn’t help.
I have the feeling that it is related to the latest Compilation time improvements in 1.11
which states:
This change allows us to mark
import
s andrequire
s as “exports dependencies” instead of “compile time” dependencies
Does somebody know how to make my MyApp.Config
module available at compile-time again?