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

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
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
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
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
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
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

We're in Beta

About us Mission Statement