Mix task: calling a function outside the application

Hi! I have a library called :my_library (or MyLibrary ) that’s installed as dependency for my app :my_app (or MyApp ).

MyLibrary has a mix task which calls a function defined in MyApp.Collection.create , passing the args from mix task.

I’m curious how can I run that function from MyLibrary mix task, since it’s throwing UndefinedFunctionError (since MyLibrary don’t know anything about MyApp from mix task)

** (UndefinedFunctionError) function MyApp.Collection.create/1 is undefined (module MyApp.Collection.create/1 is not available)
...

Looks like you’ve got it upside down :upside_down_face: . Can you pass an arg to the task instead or move the task into the app?

Notes on using application config:

https://hexdocs.pm/elixir/design-anti-patterns.html#using-application-configuration-for-libraries

1 Like