liveBook · Manning

Dependency

As explained in Elixir in Action, Third Edition

A dependency is a component, resource, or prerequisite that another software component relies on.

A dependency is a component, resource, or prerequisite that another software component relies on. In an Elixir project, external dependencies are declared in mix.exs and resolved by Mix. section 11.2.1 section 11.1.1

A practical dependency workflow includes:

  • Declare a library as a tuple containing its application atom and version requirement. section 11.2.1
  • Fetch dependencies with mix deps.get; Mix resolves recursive dependencies and records exact versions in mix.lock. section 11.2.1
  • Prefer a library that provides the needed abstraction: plug_cowboy exposes Plug while hiding Cowboy’s server details, including both transitively. section 11.3.1
  • Compile the project and its dependencies with mix compile. section 11.2.1

Declaring Poolboy

defp deps do [{:poolboy, "~> 1.5"}] end The requirement accepts version 1.5 and later 1.x releases. Mix can compile Poolboy even though it is an Erlang library. section 11.2.1

Listing 11.8 External dependencies for the web server (todo_web/mix.exs)
defmodule Todo.Mixfile do
  ...
 
  defp deps do
    [
      {:poolboy, "~> 1.5"},
      {:plug_cowboy, "~> 2.6"}    #1
    ]
  end
end

Use this configuration to compare direct declarations with automatically resolved transitive dependencies. section 11.3.1

How Elixir in Action, Third Edition covers it

How deep it goes
Explains declaration, version requirements, fetching, locking, compilation, and transitive resolution without detailing resolver internals.
Examples
Uses Poolboy, plug_cowboy, mix.exs declarations, mix deps.get, mix compile, and mix.lock.
What it assumes
Assumes an Elixir project using Mix and introduces external-library declarations, version requirements, and application dependencies.
What you can do after
Operate and configure dependencies through mix.exs, Mix commands, Hex, and a committed mix.lock file.
How it connects
Connects dependencies with Mix, Hex, mix.lock, OTP applications, Plug, Cowboy, and transitive dependencies.

Also explained in

Compare how 27 books explain dependency →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elixir in Action, Third Edition. The section links point to the parts of the book it draws on.