DEV Community

Cover image for How to import a local module dependency in Elixir
Adam Davis
Adam Davis

Posted on • Originally published at brewinstallbuzzwords.com

How to import a local module dependency in Elixir

When you’re in the process of developing a package, it can be useful to be able to import it into another project locally without having to publish it first. By doing this, you can test it within the context of a larger project instead of relying entirely on unit tests.

This guide will show you how to take an Elixir package you’ve made locally and import it into another project using the file path.

Name the dependency

Open the mix.exs file. Look for the project definition, which should look like this:

def project do
  [
    app: :my_dependency,
    version: "0.1.0",
    ...
  ]
end
Enter fullscreen mode Exit fullscreen mode

Make sure to update the name of the app property to whatever you would like to import this package as in other projects.

Get the file path

Copy the complete file path to the root of your package.

Import the package

In the project you’d like to import the package, open your mix.exs file.

Find deps and add your package to the array using the path property:

defp deps do
  [
    {:word_list, path: "/path/to/your_dependency"}
  ]
end
Enter fullscreen mode Exit fullscreen mode

Test with iex

Now you can test whether your project has access to the dependency. Run an iex shell for your project.

iex -S mix
Enter fullscreen mode Exit fullscreen mode

Then, check that you have the ability to run functions from your dependency.

iex> MyDependency.hello
:world
Enter fullscreen mode Exit fullscreen mode

More content

Oldest comments (0)