If you haven't defined an :app_name
, as it was in my case, I've managed to make this work:
defmodule MyModule do
@otp_app Mix.Project.config[:app]
def my_func do
Application.app_dir(@otp_app, "priv/path/to/file")
end
end
Then I could run my tests (mix test
) in both root level of my umbrella project and in my app that was using the priv
directory.
Update:
I've had issue because I had an escript
that I wanted to use data from priv
, so I ended up reading the file at compile time and then my problem was gone:
@otp_app Mix.Project.config()[:app]
@file_contents File.stream!(Application.app_dir(@otp_app, "priv/path/tofile"))
and in my method:
def read_file do
@file_contents
|> do_something
# ...
end