stevensonmt

stevensonmt

Cannot use function in custom mix task defined in same app

I have an app with the following structure:

mix.exs
lib
  |_my_app.ex
  |_mix/tasks/my_mix_task.ex

The file lib/my_app.ex defines a module MyApp with a function load. The mix/tasks/my_mix_task.ex includes

defmodule Mix.Tasks.MyApp.MyTask do 
  use Mix.Task
 
 def run(_) do 
   Mix.Task.run("app.start")
    # IO stuff
   MyApp.load()
 end
end

When I run mix my_app.my_task the call to MyApp.load() gives

UndefinedFunctionError … (module MyApp is not available)

unless I run it from the root directory of my_app, in which case I get

(UndefinedFunctionError) function Hex.Mix.overridden_deps/1 is undefined (module Hex.Mix is not available)

I’ve run mix archive.build and mix archive.install to make it available globally.

Any ideas?

Marked As Solved

stevensonmt

stevensonmt

I’m an idiot who should RTFM:

For instance, archives do not include dependencies, as those would conflict with any dependency in a Mix project after the archive is installed.

Where Next?

Popular in Questions Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement