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?
zachdaniel
I’m sorry, I’m having trouble understanding your question ![]()
Another way my lib can, he/she changes the mix file and your code can re-compile in runtime without any downtime? yes?
I believe the answer to this question is yes. You can run this to install any deps added to the mix.exs file without downtime. But if the app is currently running I’m not sure if there will be weird behavior from the Mix.Project.pop/1 call. Hard to say.
shahryarjb
Thank you. Aha, this is the answer I need.
So I should re-check it. I do not care about state if lost! because hot coding is very hard for full project, hot coding just useful for one or 2 modules manually and it is very harder in release mode!
Thank you and sorry for my english I am not native, it wasted your time ![]()
![]()
Anyway, Ash means bear in my mother tongue lang ![]()








