I have an umbrella project (my_app
) like this:
├── README.md
├── apps
│ ├── app_one
│ | └── mix.exs
│ ├── app_two
| | └── mix.exs
│ └── ...
├── config
└── mix.exs
I want to get the name of the currently running app,
for example: app_one
, app_two
.
when i use:Mix.Project.get.project[:app]
i always get the main project name my_app
.
How can i do that?
You can get the application to which the a module belongs to using :application.get_application/1
. If you pass __MODULE__
as the first argument, you'll get the application the current module belongs to.
$ cat apps/a/lib/a.ex
defmodule A do
def hello do
:application.get_application(__MODULE__)
end
end
$ cat apps/b/lib/b.ex
defmodule B do
def hello do
:application.get_application(__MODULE__)
end
end
$ iex -S mix
iex(1)> A.hello
{:ok, :a}
iex(2)> B.hello
{:ok, :b}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With