How to merge multiple mix.exs files in umbrella project into single mix.exs file

In my elixir project Demo(umbrella project) I have multiple mix.exs file such as

Demo/apps/MyApp1/mix.exs

  def project do
    [
      app: :myapp1,
      version: "1.5.0",
      build_path: "../../_build",
      config_path: "../../config/config.exs",
      deps_path: "../../deps",
      lockfile: "../../mix.lock",
      elixir: "~> 1.8",
      start_permanent: Mix.env == :prod,
      deps: deps()
    ]
  end

  def application do
    [
      extra_applications: [:logger, :runtime_tools],
      mod: {MyApp1.Application, []}
    ]
  end

  defp deps do
    [
      -----------------
      -----------------	
    ]
  end
end

Demo/apps/MyApp2/mix.exs

  def project do
    [
      app: :myapp2,
      version: "1.5.0",
      build_path: "../../_build",
      config_path: "../../config/config.exs",
      deps_path: "../../deps",
      lockfile: "../../mix.lock",
      elixir: "~> 1.8",
      start_permanent: Mix.env == :prod,
      deps: deps()
    ]
  end

  def application do
    [
      extra_applications: [:logger, :runtime_tools],
      mod: {MyApp2.Application, []}
    ]
  end

  defp deps do
    [
      -----------------
      -----------------	
    ]
  end
end

and in root mix.exs file has

  def project do
    [
      apps_path: "apps",
      start_permanent: Mix.env == :prod,
      deps: deps()
    ]
  end

  defp deps do
    [
      ------------------,
    ]
  end
end

How can I make a single root mix.exs with the contents from MyApp1 and MyApp2?
Can someone help me with this?

You can’t and you shouldn’t. The Mix.exs is configuration for the app in the umbrella, so it doesn’t make sense to have two apps share config because they are different apps.

Also be aware that deps defined in the root mix.exs aren’t available to the apps in the umbrella.

I guess the question is why do you want to do this? What are you trying to achieve?

Thank you for replying…
I want to remove the umbrella structure from the project with a single mix.exs as well as config file

Are you trying to move from an umbrella project to a normal project? You could do that but it would require more than merging the mix.exs files.

yes exactly… I want to move from an umbrella project to a normal project…

It may be helpful for you to compare the umbrella and non-umbrella version of a new Phoenix project e.g. by running:

mix phx.new x
mv x x-normal
mix phx.new --umbrella x
mv x x-umbrella

I went through a reverse procedure and seeing the structure of both is a great way to kick start. Depending on a project size, you may have quite a few steps ahead of you.

1 Like