Load application and modules from another mix project

Good day, everyone! I’m starting to develop my first package (migrator) and I want to execute code (exs) from another mix projects that will be used mine. My idea is simple: I defined special modules in priv directory in my project and call them with mix tasks from separated package.

But I got two problems in implementation of its package:

  • I detected my project name in migrator with Mix.Project.config()[:app] (for loading priv exs files), but couldn’t locate it with Application.app_dir. I got ArgumentError: unknown application error.

  • If I manually set project path and load exs files with Code.load_file/1, I can’t execute my project code in module functions, because they didn’t define in migrator.

I think, that I need to somehow load code of my project for execution in migrator context, but I haven’t got idea how to do it.

Please advise how to correct these errors. Thank you!

P.S. my drafts: https://github.com/RuBAN-GT/memento_migrator

I found solution. My assumptions about loading was true. After debug ecto_sql I found easy solution: to call loadpaths task with mix in own task code.

4 Likes