kip
Mix.Task.run "deps.compile", ["dep_name", "--force"] not compiling
I have a dep that might need recompiling when the host app configuration changes. That requires a forced compile since by design deps aren’t automatically recompiled (which is the right strategy).
At the command line I can force recompile fine. But from IEx calling Mix.Task.run/2 I cannot. From the command line:
$ mix deps.compile ex_cldr --force
==> ex_cldr
Compiling 2 files (.erl)
Compiling 31 files (.ex)
Generating Cldr for 6 locales named ["en-001", "it", "pl", "root", "ru", ...] with a default locale named "en-001"
Generated ex_cldr app
From IEx shell:
$ iex -S mix
Erlang/OTP 20 [erts-9.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
iex(1)> Mix.Task.run "deps.compile", [:ex_cldr, "--force"]
:ok
…but no compilation takes place.
Any advice on how I specify the args to Mix.Task.run/2 so that it force compiles would be most appreciated.
Most Liked
ericmj
This seems to be an Elixir bug. When the --force flag is given the compile task for the dependency should be reenabled, by default a task is called only once per project/dependency and in this case it seems to have been called earlier at some point.
You have the same bug in your example, you should call Mix.Task.rerun since the task may have already run when mix was started.
zachdaniel
Was just about to post back here with my current solution which is probably a very very ugly hack, but it does work:
case Mix.shell().cmd("mix deps.get") do
0 ->
Mix.Task.reenable("compile")
Mix.Task.run("compile")
Mix.Project.clear_deps_cache()
Mix.Project.pop()
"mix.exs"
|> File.read!()
|> Code.eval_string([], file: Path.expand("mix.exs"))
Mix.Task.run("deps.compile", Enum.map(install_list, &to_string/1))
Mix.Task.reenable("compile")
Mix.Task.run("compile")
exit_code ->
Mix.shell().info("""
mix deps.get returned exited with code: `#{exit_code}`
""")
end
zachdaniel
Not sure I fully understand the question, sorry.
A brief explanation of what I need to do is: I add a dependency to the mix.exs file, and I need to fetch it and look for a mix task defined by it. So I need to add a dep, get it with mix deps.get and then compile it with mix deps.compile. My use case is quite limited, as I know that the app will shut down after running my mix task, so it’s not really a problem if it ends up in a weird state. But this is happening at runtime, not at compile time (since its in a mix task.
Does that answer your question?
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









