Code Dependencies
Learn about a few code dependencies in Elixir.
We'll cover the following
The Mix tool is smart when it compiles a project. It analyzes the dependencies between our source files and only recompiles a file when it has changed or a file it depends on has changed. As developers, we can also access this dependency information, gaining valuable insights into our code. We do this with the mix xref
commands:
-
The
mix xref unreachable
command lists functions that are unknown at the time they are called. -
The
mix xref warnings
command lists warnings associated with dependencies (for example, calls to unknown functions). -
The
mix xref callers Mod | Mod.func | Mod.func/arity
command lists the callers to a module or function:
$ mix xref callers Logger
mix xref callers Logger
web/controllers/page_controller.ex:1: Logger.bare_log/3
web/controllers/page_controller.ex:1: Logger.debug/1
lib/webapp/endpoint.ex:1: Logger.bare_log/3
lib/webapp/endpoint.ex:1: Logger.error/1
- The
mix xref graph
command shows the dependency tree for the application:
Get hands-on with 1400+ tech skills courses.