Hi everyone,
I have an umbrella project with 2 apps: first, `ledger`, is using Ecto and the 2nd, `money`, one is mostly just a struct with some functions.
Now, the 2nd app has an "optional" Ecto support, it defines a custom Ecto.Type for that struct. The Ecto support is wrapped in a `if Code.ensure_loaded?(Ecto.Type)` because I didn't want to specify Ecto as a dependency.
When I run the tests from the root of the app everything works well.
Now, when I `cd apps/money && touch && lib/money/ecto.ex && mix test` that works too. But when I then re-compile from within the 1st app: `cd apps/ledger && mix test` my custom types isn't defined. Which makes sense, because when I compiled the 2nd app, `Ecto.Type` wasn't available at that time and some the generated .beam does not have that.
My temporary solution is to just recompile stuff from the root. Another solution is to introduce `apps/ledger/lib/money_ext.ex` and define the extension there - the downside is that I'd rather keep that stuff in the `money` app.
Finally, I could just make `money` depend on Ecto directly, but I'm wondering if there's another way. If I'd ever publish the package on Hex I wouldn't want to depend on `ecto` directly (make that optional instead) and so I'd likely end up with the similar `if Code.ensure_loaded` guard.
Thanks,
Wojtek