A local dependency with 'path' doesn't work properly

I have something like this:


  defp deps do
    [
      {[.......]},
    ] ++ private_deps()
  end

  defp private_deps do
    case System.get_env("USE_LOCAL_DEPS") do
      "true" ->
          # IO.puts("test1") # this will get hit
        [
          {:lib1, path: "../lib1"}
        ]

      _ ->
          # [.........]
        [
          {:lib1, git: "gitlab url here [.....]"}
        ]
    end
  end

I’ll change something in lib1, re-run an application

    USE_LOCAL_DEPS=true mix phx.server

and the changes made in lib1 won’t be reflected in it.

This doesn’t work either:

USE_LOCAL_DEPS=true mix deps.update lib1

as it’ll try to fetch all the dependencies from hex.pm

Neither this will

USE_LOCAL_DEPS=true mix deps.get lib1

as the changes in the lib1 still won’t be fetched from “…/lib1”

What’s the matter?

Did you try USE_LOCAL_DEPS=true mix deps.compile lib1 after changing lib1?

It doesn’t work:

USE_LOCAL_DEPS=true mix deps.compile lib1

** (Mix) Cannot compile dependency :lib1 because it isn't available, run "mix deps.get" first

And

USE_LOCAL_DEPS=true mix deps.get lib1
Resolving Hex dependencies...
Dependency resolution completed:
Unchanged:
  certifi 2.6.1
  cowboy 2.8.0
  cowboy_telemetry 0.3.1

[....lib1 hasn't appeared anywhere at all ...]

If it’s a path the package won’t show up in the deps.get output and it won’t be in the deps directory, but run iex or something and you should be able to verify the local dep is available.

1 Like

I’ve removed _build and deps, recompiled everything – to no avail. The code in deps/lib1 is still the old one

Why does it try to fetch the dependency from gitlab rather than use it locally?

$ USE_LOCAL_DEPS=true mix phx.server

    Unchecked dependencies for environment dev:
    * lib1 (https://****:****@gitlab.com/my_user123/lib1.git)
      the dependency is not available, run "mix deps.get"
    ** (Mix) Can't continue due to errors on dependencies

In total, it’ll work properly with the dependency at gitlab only.

Actually, the llib1 also uses a dependency - lib2, in the same manner - locally and from gitlab.

override: true doesn’t cause the dependency to be recompiled each time, it just overrides conflicts when other packages depend on a different version of the overridden package.

@ojinari What you’re trying to do should work. Maybe there’s a problem somewhere else in your mix.exs. Maybe if you showed the rest of your mix.exs we could help spot the issue. Also I would use USE_LOCAL_DEPS=true mix deps.tree to debug what is happening. With a correctly set up :path dependency you should see output like ├── exsync (~/dev/forks/exsync) (where ~/dev/forks/exsync is the :path).

If what you are trying to achieve is to override the remote dependency for localhost development or debug, then what I use always is:

cp -r deps/dep_name lib/

This will make a copy of the dependency available in your project and when compiling they will take precedence over the one in the deps folder.

I like this approach because I don’t need to touch in the mix.exs file.