3

I was trying to install Addict, so I added to mix.ex its latest version (as in Hex):

{:addict, ">= 0.1.0"}

Then, I have run mix reps.get and got an error:

Looking up alternatives for conflicting requirements on ecto

From mix.lock: 1.0.0
  From addict v0.1.0: ~> 0.9
** (Mix) Hex dependency resolution failed, relax the version requirements or unlock dependencies

I tried to do that in mix.lock but wasn't able to overcome that because this error appeared:

(Mix) Unknown package version ecto v0.0.9 in lockfile

What's the best way to overcome this?

Paulo Janeiro
  • 3,181
  • 4
  • 28
  • 46

1 Answers1

4

You can set a dependency to override with the override flag:

defp deps do
  ...
   {:ecto, "~> 1.0.0", override: true},
   {:addict, "~> 0.1.0"},
  ...
end

From the docs:

:override - if set to true the dependency will override any other definitions of itself by other dependencies

This means that even though addict sets the version to 0.9.0 - the 1.0.0 version will be used. This could cause issues if addict is using a function in Ecto that is now deprecated.

Gazler
  • 83,029
  • 18
  • 279
  • 245
  • Thank you again. I added {:ecto, ">= 1.0.0", override: true} to mix.exs and although the error was with mix.lock it solved it. What's the role of mix.lock? Also, can you be kind enough to explain what's the difference between the ~> and >= operator? – Paulo Janeiro Sep 04 '15 at 14:46
  • 1
    The `mix.lock` file is there to lock the dependency down. This means that if you create a project and I clone it down, the dependencies I fetch are the same ones that you have. It will store the exact version numbers instead of the `version constraints` that you specify in `mix.exs` - you shouldn't modify `mix.lock` manually. You should probably use `~>` instead of `>=` The differences are explained in http://stackoverflow.com/questions/4292905/what-is-the-difference-between-and-when-specifying-rubygem-in-gemfile – Gazler Sep 04 '15 at 14:55