Thanks for the reminder - got kinda busy today 
No need to create an example repo - itβs easily enough reproducible.
So the digging around the Mix.target
PR commit: https://github.com/elixir-lang/elixir/commit/2e576f67a00164d88e2e242e523dc3b5c1a8a5db
targets:
is the correct syntax (since you can also pass a list targets: [:postgres, :absinthe]
). I think before I was looking at some pre-merged code.
Anyways:
$ mix deps.get --target postgres
is the correct syntax to fetch target deps instead of MIX_TARGET=postgres mix deps.get
And with that it does give us a couple warnings:
warning: the dependency :phoenix_ecto is duplicated at the top level, please remove one of them
But it does appear to pull the correct target version:
$ mix deps.tree --target postgres
warning: the dependency :phoenix_ecto is duplicated at the top level, please remove one of them
warning: the dependency :phoenix_ecto is duplicated at the top level, please remove one of them
phx_targets_test
...
βββ phoenix_ecto ~> 4.0 (Hex package)
βββ ecto ~> 2.2 or ~> 3.0 (Hex package)
βββ phoenix_html ~> 2.9 (Hex package)
βββ plug ~> 1.0 (Hex package)
and then for the mssql target:
$ mix deps.get --target mssql
warning: the dependency :phoenix_ecto is duplicated at the top level, please remove one of them
Resolving Hex dependencies...
Dependency resolution completed:
Unchanged:
...
Downgraded:
phoenix_ecto 4.0.0 => 3.5.0 RETIRED!
(invalid)
warning: the dependency :phoenix_ecto is duplicated at the top level, please remove one of them
* Updating phoenix_ecto (Hex package)
and then confirm with the target deps.tree:
$ mix deps.tree --target mssql
warning: the dependency :phoenix_ecto is duplicated at the top level, please remove one of them
warning: the dependency :phoenix_ecto is duplicated at the top level, please remove one of them
phx_targets_test
...
βββ phoenix_ecto ~> 3.0 (Hex package)
βββ ecto ~> 3.0 (Hex package)
βββ phoenix_html ~> 2.9 (Hex package)
βββ plug ~> 1.0 (Hex package)
Then you execute using the MIX_TARGET
variable:
$ MIX_TARGET=mssql mix phx.server
and where I thought it would get murky about remembering the version from which target I had last fetched the deps for, it reminds you at compile time:
$ MIX_TARGET=postgres mix phx.server
...
Unchecked dependencies for environment dev:
* phoenix_ecto (Hex package)
the dependency does not match the requirement "~> 4.0", got "3.5.0"
** (Mix) Can't continue due to errors on dependencies
Good stuff.