Hex - is there a way to use a completely local dependency in a Elixir project?

Is there a way to use a completely local dependency in a Elixir project? A dependency shouldn’t be uploaded to any git cloud hosting including a private cloud repository at github, gitlab and so on.

You can use path dependency… it allows to use a dependency relative to main application path (or absolute path).


Local path dependencies are described here: https://hexdocs.pm/mix/Mix.Tasks.Deps.html


However I feel that sometimes like Rebar3 _checkouts would be useful, especially during debugging of the dependencies, so I do not override the :deps field and being prone to shipping PR with link to local package.


You can modify files in deps/ and then run mix deps.compile APP to recompile it.


Well, I rarely want to do that, as this do not allow me to make the changes into PR later. I would prefer to clone it to separate directory and then symlink. This makes it much easier than to modify the deps and then wondering how to move that changes into the project itself.

For cases like that, I’d sometimes do the following:

defp deps() do
    ecto: ecto_dep()

defp ecto_dep() do
  if path = System.get_env("ECTO_PATH") do
    {:ecto, path: path}
    {:ecto, "~> 3.0"}

Which is handy, if everyone will need to have such step. But if I need it for only one dependency that will be “fix and forget” then there is no simple solution that I am aware of. And it would be useful solution for some people.

In the case where I need to actually make changes to a dependency I like that I need to explicitly declare it as a path dependency. It’s very little work compared to making a PR and with an explicit dep I cannot accidentally commit changes to the project without updating the dep or reverting changes that depend on my local checkout changes.


that’ll recompile the main APP, though, plus a dependency

Working with :path dependencies is awesone as you do not have to work in the deps directory (the dependency is not copied here). You will directly edit the code of the dependency in its own directory. And that is great to work on a library and an app at the same time!

And you also don’t have to call mix deps.compile. For example it is automatically compiled whenever the code changes between calls to mix test.

(that’s how it works on my machine but your mileage may vary)

mix deps.compile APP will compiled the dependency with the name APP, but any changes in dependencies will cause the main project to be compiled since the project depends on its dependencies of course.