Hello,

I think if you define the dependency on ecto as optional in the “money” app 
this will ensure ecto is available by the time that dependency is compiled.

You can do that with {:ecto, “~> 2.0”, optional: true} as the dependency 
declaration.

Michał.

> On 12 Jul 2016, at 22:07, Wojtek Mach <[email protected]> wrote:
> 
> 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.
> See: 
> https://github.com/wojtekmach/umbrella_bug/blob/3dca063ee4bb3f4cc020708c218e31c13d2ad4a6/apps/money/lib/money/ecto.ex#L1.
> 
> 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.
> 
> All code is on github: 
> https://github.com/wojtekmach/umbrella_bug/tree/3dca063ee4bb3f4cc020708c218e31c13d2ad4a6
> 
> Thanks,
> Wojtek
> 
> 
> --
> You received this message because you are subscribed to the Google Groups 
> "elixir-lang-talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> <mailto:[email protected]>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/elixir-lang-talk/06404fb8-363c-4942-af28-a96e1b2d62f9%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/elixir-lang-talk/06404fb8-363c-4942-af28-a96e1b2d62f9%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-talk/EBDD460F-BC96-4F38-9CD0-E5E7AA9A2300%40muskala.eu.
For more options, visit https://groups.google.com/d/optout.

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to