Execute runtime.exs in custom mix task


I need to select a local SQLite database outside my Phoenix project.
So I set some configuration options based on enviroment variables in runtime.exs.
For BASE_PATH=/path/to/my/working/dir mix phx.server it works great.

And now I need a custom mix task (tests.create) for some low level file stuff.

When I exectue BASE_PATH=/path/to/my/working/dir mix tests.create my config in runtime.exs is ignored.

How execute runtime.exs in my mix task?

A student of mine (jojofreddy) pointed me to this:

This magic line

def run(args) do
  # do work

solved the problem.

You can also use @requirements module attribute for this purpose:

@requirements ["app.config"]