Understanding Elixir Mix
This and the other “Deck” posts are a repurposing of flashcard study decks to Q&A blog posts.
What do Elixir developers use Mix for?
Many different things. Mix is used for creating Elixir apps, for compiling Elixir apps after code changes, to run an apps test suite, to resolve third party dependency compatibility, and for executing custom tasks.What does it mean to say Mix is an Elixir executable?
Executable files are files that can be run by a computer's operating system, they are not data files like your projects source code. Elixir has its own executable and Mix is another executable built on top of Elixir's.How does Mix help with dependency management?
Through an integration with Hex package mananger Mix applications can use third party dependencies. Hex is the tool doing the package compatibility resolution. Mix provides a way to declare dependencies and command line tasks for installing, removing, or updating dependencies, these tasks use Hex to accomplish this.How can you tell Mix that you are using third party dependencies in your project?
In your applications `mix.exs` file you can declare a private `deps` function which includes a list of your dependencies and then execute `mix deps.get` to install them.defmodule MyApp.MixProject do
use Mix.Project
def project do
[ deps: deps() ]
end
defp deps do
[ {:ecto, "~> 2.0"} ]
end
end
How to you find the PATH that the Mix executable exists on macOS?
You can do this through the command line by executing `which mix`.Below is an example of a custom Mix task, how would you invoke this task?
defmodule Mix.Tasks.Hello do
use Mix.Task
def run(_) do
Mix.shell().info("Hello world")
end
end
On the command line execute mix hello
.