Elixir/Phoenix Mix Tip #1: mix deps.unlock


Here comes the first in a series of blog posts on using Mix with your Elixir project.

Did you know you can update individual Elixir libraries using the outstanding build tool and dependency manager that is Mix?

I didn’t either.

What is Mix?

Straight out of the Programming Elixir 1.3 book:

Mix is a command line utility that manages Elixir projects. Use it to create new projects, manage a project’s dependencies, run tests, and run your code.

What is Elixir?
Elixir is a dynamic, functional language designed for building scalable and maintainable applications. Elixir leverages the Erlang virtual machine, known as BEAM. I did a talk on learning Elixir recently. Learn more in this blog post.

If you use the excellent Calendar Elixir library by Lau Taarnskov you will need to update the tzdata library on which it depends to version 0.5.11 to avoid error messages like this:

iex(1)> [debug] Tzdata polling for update.
18 Mar 15:44:16 - info: compiling
[error] Task #PID started from :tzdata_release_updater terminating
** (ArgumentError) argument error
(tzdata) lib/tzdata/data_loader.ex:28: Tzdata.DataLoader.content_length_from_headers/1
(tzdata) lib/tzdata/data_loader.ex:50: http://Tzdata.DataLoader.do _latest_file_size/1
(tzdata) lib/tzdata/release_updater.ex:43: Tzdata.ReleaseUpdater.loaded_tzdata_matches_iana_file_size?/0
(tzdata) lib/tzdata/release_updater.ex:31: Tzdata.ReleaseUpdater.poll_for_update/0
(tzdata) lib/tzdata/release_updater.ex:22: Tzdata.ReleaseUpdater.check_if_time_to_update/0
(elixir) lib/task/supervised.ex:94: http://Task.Supervised.do _apply/2
(elixir) lib/task/supervised.ex:45: Task.Supervised.reply/5
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Function: #Function<1.130382589/0 in Tzdata.ReleaseUpdater.init/1>
Args: []

What is the Tzdata library?

The Tzdata library manages the the timezone database for Elixir projects. If you use it, you will grow accustomed to its diligent downloading of the latest timezone database files from the Internet Assigned Numbers Authority (IANA) when you start your project for the first time each day.

I use Calendar on Assenty to handle dates, times and, timezones. Assenty is a real-time Q&A web service, written to solve the problem of answering questions from audiences at events.

Every time you register an event and create a question board on Assenty, you use the Tzdata library and this timezone and their countries list Tau kindly compiled for me back in August last year when I wanted to add the feature.

Thanks again Lau! Your gesture helped Assenty take its first steps towards internationalisation.

In case you were wondering, here’s how you specify the timezone for your question board in the Assenty dashboard:

So, how to fix that error? Another Lau suggestion, and it’s quite easy!

The easiest way to get the newest version of tzdata is:

mix deps.unlock tzdata
mix deps.get

And then confirm that version 0.5.11 is downloaded and present in the mix.lock file.

That’s it!

And there you have it, to update individual Elixir libraries simply run ‘mix deps.unlock’ and you’re off and running.

On Mix tips and tricks, I also saw this little gem on Twitter, 'mix hex.outdated'. Brought to my attention by the illustrious Mike Groseclose

Basically, you use it to find out which of your Elixir dependencies need updating.

Don’t go crazy with the updating 🙂

Hope you enjoyed the tip(s). Any questions, tips, comments, leave a comment!