Elixir Umbrella as Dependency

I have the following mix.exs file for my Phoenix application. The final dep is " {:worksolvr_services, git: "https://github.com/worksolvr/worksolvr-elixir-services.git"}," which is an umbrella app containing a number of isolated service applications. When I try to run mix phx.server I receive the following error:

** (Mix) Could not start application account_service: could not find application file: account_service.app

Is this configuration possible and if so what am I missing in the configuration?

Thanks,
Peter

defmodule WorksolvrGraphqlServer.MixProject do
  use Mix.Project

  def project do
    [
      app: :worksolvr_graphql_server,
      version: "0.1.0",
      elixir: "~> 1.5",
      elixirc_paths: elixirc_paths(Mix.env()),
      compilers: [:phoenix, :gettext] ++ Mix.compilers(),
      start_permanent: Mix.env() == :prod,
      deps: deps()
    ]
  end

  # Configuration for the OTP application.
  #
  # Type `mix help compile.app` for more information.
  def application do
    [
      mod: {WorksolvrGraphqlServer.Application, []},
      extra_applications: [:logger, :runtime_tools]
    ]
  end

  # Specifies which paths to compile per environment.
  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_), do: ["lib"]

  # Specifies your project dependencies.
  #
  # Type `mix help deps` for examples and options.
  defp deps do
    [
      {:phoenix, "~> 1.4.1"},
      {:phoenix_pubsub, "~> 1.1"},
      {:phoenix_html, "~> 2.11"},
      {:phoenix_live_reload, "~> 1.2", only: :dev},
      {:gettext, "~> 0.11"},
      {:jason, "~> 1.0"},
      {:plug_cowboy, "~> 2.0"},
      {:distillery, "~> 1.5.5"},
      {:absinthe, "~> 1.4.2"},
      {:absinthe_plug, "~> 1.4.0"},
      {:absinthe_phoenix, "~> 1.4.0"},
      {:absinthe_relay, "~> 1.4.0"},
      {:worksolvr_services, git: "https://github.com/worksolvr/worksolvr-elixir-services.git"},
    ]
  end
end

Thats not possible, umbrella project is not an application and thus it cannot be added as a dependency.

2 Likes

Thank you @wojtekmach! The services are too small to create as individual repos, however, I wanted to separate them from the Phoenix layer itself. I guess for the time being I will create an umbrella add that includes Phoenix as well as the services.

Peter

Perhaps you can use the :sparse option to your git dependency?

  • :sparse - checkout a single directory inside the Git repository and use it as your Mix dependency. Search “sparse git checkouts” for more information.
1 Like

It is pretty tricky to put an umbrella project as a dependency, we just tried it out recently, hope it helps.

Firstly of all, add your umbrella repo as a dependency with app: false:

  defp deps do
    [
      ...
      {:your_umbrella_name, git: "git@github.com:yourcomany/your_project", app: false},
    ]
  end

Then for the apps defined in your umbrella app, you need to add the ones you used in your project:

  def application do
    [
      extra_applications: [
        :logger,
        :app1_in_umbrella,
        :app2_in_umbrella,
        ...
      ],
      mod: {YourNew.Application, []}
    ]
  end

That would make things work.

2 Likes

Hi @tyrchen!

Thank you for providing this solution.

The one thing I am noticing is that it doesn’t seem to load the configs from the app pulled from the umbrella app. I have ecto configured in one of the apps and it doesn’t recognize the database config. If I, however, copy the config into the top level application it runs just fine.

Thanks,
Peter

Configuration is always local to a mix project and therefore never loaded from dependencies, so this is expected.

3 Likes