Add a New Dependency

Learn how to add a new dependency in the game engine.

We'll cover the following

The game engine

Now that we have a new Application to act as the web interface, we need to bring the game engine in as a dependency. The interface needs to have access to all the game logic we wrote so far in the course. In particular, it must be able to see all the public functions in the IslandsEngine.Game module.

This works just like any other dependency in Elixir and is about as easy as it can possibly be. Only two steps are involved.

We need to compile IslandsEngine with the rest of the project and start it when we start the IslandsInterface Application.

Changes to mix.exs

To make :islands_engine a compile-time dependency, we’ve added it to the deps/0 function in /islands_interface/mix.exs:

defp deps do [
  {:phoenix, "~> 1.3.0"},
  {:phoenix_pubsub, "~> 1.0"},
  {:phoenix_html, "~> 2.10"}, 
  {:phoenix_live_reload, "~> 1.0", only: :dev},
  {:gettext, "~> 0.11"},
  {:cowboy, "~> 1.0"},
  {:islands_engine, path: "../islands_engine"}
]
end

Notice that we use a path dependency for :islands_engine. This allows us to provide the pathname to a project on the local filesystem. The Elixir package manager, Hex, takes care of the rest. That’s it. We can give this a try in the console by running iex -S mix phx.server at the root of the islands_interface project.

Get hands-on with 1400+ tech skills courses.