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.

1 Like

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

6 Likes

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

7 Likes

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.

3 Likes

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

3 Likes

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()
  ]
end

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

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.

4 Likes

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)

3 Likes

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.

3 Likes

I’ve added a path dependency to a directory outside my phoenix app but to get any changes to be reflected in phoenix I need to stop/start phoenix. Is there a way to have the changes reflected automatically without the stop/start?

Here’s my what I have for the path dependency:

  defp deps do
    [
      {:petal_components, path: "../petal_components"}
    ]
  end
3 Likes

Figured it out. If you’re using path dep and dont want to have to start stop your phoenix app to have changes reflected you just need to add the path to elixirc_paths in mix.exs e.g.

  # Specifies which paths to compile per environment.
  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_), do: ["lib", "/Path/to/dependency"]
7 Likes