Dependancy compile-time behavior


I have a stand-alone project that I want to now run as a dependency. However, during mix deps.compile I’d like the dependency to:

  1. Figure out it’s actually a dependency (rather than the “main” application)
  2. Read the “mix.exs” data from the “parent” project (i.e. the ParentProject.MixFile module)

Now I can do 1. by creating an alias in the dependency mix.exs, something like:

  defp aliases do
      compile:  ["compile", "run priv/magic_goes_here.exs"]

And have priv/magic_goes_here.exs do something like:

if Path.dirname(File.cwd!()) == Mix.Project.deps_path(),
   do: dependancy_logic() 

What I now want to do is read the information from the “parent” project.

Any suggestions?


If you’re already modifying configuration in the parent application, add configuration that tells the dependency it’s a dependency. 100% less magic.