How can update "mix.exs" in elixir?

I am try to migrate these days to elixir, and I have existing project, I want to learn graphql api with absinthe. it has mix.exs file like that:

defmodule BlogApp.Mixfile do
  use Mix.Project

  def project do
    [app: :blog_app,
     version: "0.0.1",
     elixir: "~> 1.4",
     elixirc_paths: elixirc_paths(Mix.env),
     compilers: [:phoenix, :gettext] ++ Mix.compilers,
     build_embedded: Mix.env == :prod,
     start_permanent: Mix.env == :prod,
     aliases: aliases(),
     deps: deps()]
  end

  # Configuration for the OTP application.
  #
  # Type `mix help compile.app` for more information.
  def application do
    [mod: {BlogApp.Application, []},
     extra_applications: [:logger]]
  end

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

  # Specifies your project dependencies.
  #
  # Type `mix help deps` for examples and options.
  defp deps do
    [
      {:phoenix, "~> 1.3.0-rc"},
      {:phoenix_pubsub, "~> 1.0"},
      {:phoenix_ecto, "~> 3.2"},
      {:postgrex, ">= 0.0.0"},
      {:gettext, "~> 0.11"},
      {:cowboy, "~> 1.0"},
      {:absinthe, "~> 1.3.0-rc.0"},
      {:absinthe_plug, "~> 1.3.0-rc.0"},
      {:absinthe_ecto, git: "https://github.com/absinthe-graphql/absinthe_ecto.git"},
      {:faker, "~> 0.7"},
    ]
  end

  # Aliases are shortcuts or tasks specific to the current project.
  # For example, to create, migrate and run the seeds file at once:
  #
  #     $ mix ecto.setup
  #
  # See the documentation for `Mix` for more info on aliases.
  defp aliases do
    ["ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
     "ecto.reset": ["ecto.drop", "ecto.setup"],
     "test": ["ecto.create --quiet", "ecto.migrate", "test"]]
  end
end

I know manually you can update dependencies with mix deps.get , but is it possible to update dependencies automatically?

  1. Why would you want that?
  2. What docs have you read so far?
1 Like

There seems to be some prior art here: Mix deps.add functionality - #5 by chvanikoff – But it’s old and probably requires some massaging to work with the latest Elixir.

Here’s a long recent-ish discussion on the matter: Why doesn't the Elixir core team accept `mix deps.add` proposals?

It boils down to the fact that mix.exs is executable Elixir code. So whatever you can do in Elixir, you can do in that file. That means that the deps can be in any format and modifying the file can be a big challenge. A tool could be made to handle the 90% case, and personally I would think that’s worthwhile, but others disagree (or at least disagree that such a tool should be part of Elixir). Other than the first link in my post, I don’t know of such a tool existing.

It’s a workflow that people expect from the likes of npm install, that when they run an install/update command, their versions are automatically saved to the configuration file.

2 Likes

mix.exs is not a data file like json, but code. You can use any elixir in there you want. This makes updating that file a non-trivial problem. With recent elixir version you can use GitHub - doorgan/sourceror: Utilities to manipulate Elixir source code to do so.

1 Like

tnx so much I get it , when I use mix deps.update --all, it help me, I understand now

tnx so much, I get it now :slight_smile:

For my information: what in his (or others) post pointed you to the —all flag?