I'm writing a quick Elixir script, and I'd like to use a csv library dependency. It seems a bit overkill to create a new mix project just to add in dependency management for this one library. What would you recommend? Would you go the mix project route for a simple script with a dependency?
Note: I'm not asking how to install and access dependencies globally. The question is, "would you go the mix project route..." What is the suggested approach?
Go the mix project route. Quick and dirty scripts have a way of growing into bigger projects.
Introduced as an experimental feature in Elixir 1.12, Mix.install/2 now allows you to specify a dependency directly in an Elixir script, giving you an alternative to a full-blown mix project.
Usage is quite straightforward: list your dependencies at the top of your script (in the same format that is returned from the regular deps
function in a mix project), and it will take care of downloading, compiling, and caching the dependencies for you:
Mix.install([
{:httpoison, "~> 1.8"},
:jason
])
HTTPoison.start
IO.puts(Jason.encode!(%{hello: :world}))
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With