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

6 2

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

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay