3

How can I configure applications to be loaded in run time only in a certain environment? I know I can configure a dependency only for test environment.
Is there a way to configure applications in mix.exs to be loaded only in test environment?
For example:

  def application do
    [mod: {MyApp, []},
     applications: [:phoenix]]   end

  defp deps do
    [{:phoenix, "~> 1.2.1"}] end

Can I configure phoenix application only for test environment?

Sabin Chacko
  • 713
  • 6
  • 17
fay
  • 2,086
  • 2
  • 14
  • 36
  • 2
    Use elixir 1.4. It has [application inference](https://github.com/elixir-lang/elixir/blob/v1.4/CHANGELOG.md#application-inference). It will only load the applications based on the dependencies. With that being said, your mix file is just elixir code. Feel free to throw an if in there, or write your own methods or something. You can use `Mix.env/1` to know which environment you are in. – Justin Wood Mar 16 '17 at 14:27

1 Answers1

5

As @JustinWood stated in the comments, if you're using elixir 1.4, you can use application inference to do this automatically for you.

If you have to use a version of elixir before 1.4, the way to do this would be to have something similar to the following in your mix.exs:

def application do
  [
    mod: {MyApp, []},
    applications: applications(Mix.env)
  ]
end

defp applications(:test), do: applications(:default) ++ [:test_only_app_1, :test_only_app_2]
defp applications(_),     do: [:logger, :httpoison]
Navin Peiris
  • 2,526
  • 2
  • 24
  • 25