Recompile dependency based on @external_resource

Hey there :wave:

I’m using @external_resource in a library to trigger a macro recompilation when some file is changed in the hosting application.

This is working fine when referencing the lib locally, using {:my_library, path: "../my_library"} in mix.exs: every time I touch a specific file in my application, the library gets recompiled.

But if I switch to a remote dependency (GitHub), It won’t get recompiled anymore.

Is it even possible? Maybe if I tweak the :manager option of my dependency?

1 Like

In my first implementation of ex_cldr I spent a lot of time trying to find ways to recompile a dependency when a host app changed and I never found a way to do it. And I came to believe it is an anti pattern in the elixir build system. Its possible another build tool will take another approach. But ultimately this very situation is why I have ended up with defining “backend” modules in the host application that draw on the dependency and are cleanly recompiled by mix when the @external_resource changes. Its probably not a surprise that its also the approach taken by Gettext and others.

TLDR; I suspect your objective may not be met.


Thanks! Can you show me where you’re dealing with this in your codebase?

1 Like

Can do, but its been a few years so will take me a little time to dig it out of the repo.

The “best” strategy I could come up with at the time was to roll my own “compiler” (in the Mix sense of compiler) that ran at the end of the compiler chain to force recompilation of certain modules based upon the compiler manifest or timestamps. It was very brittle.


Ok don’t waste your time then, I think I got the idea: I’ll have the host application write its own backend module, which includes my library macros to get recompiled when some files of the host app change.

I think that’s probably a good idea.

In case there’s any value in it at all (which I doubt), the cldr.compiler I wrote back in 2018 is at cldr/compile.cldr.ex at v1.8.2 · elixir-cldr/cldr · GitHub


I just implemented your solution and it’s working perfectly :ok_hand:

It also came with an extra benefit: my backend module is watched by phoenix code reloader and is recompiled, at runtime, without restarting the server in dev environment.

Many thanks!