ycherniavskyi

ycherniavskyi

How to exclude a dependency's application from running but still Include it in the Release

I’m working on two Phoenix projects: A and B. Project B provides an HTTP API that is utilized by project A. Additionally, project B implements a Util module that project A uses. This is accomplished by adding project B as a dependency from GitHub to project A.

During development, I added the following dependency to project A:

  defp deps do
    [
      # ...
      {:a, app: false, github: "c/a", branch: "main"}
    ]
  end

I used app: false to prevent loading and running the application from project B, allowing project A to only use the Util module from project B.

However, when I create a release of project A with MIX_ENV="prod" mix release, I encounter an error when executing ./_build/prod/rel/a/bin/a start:

(CompileError) _build/prod/rel/a/releases/0.1.0/runtime.exs:100: module RuntimeConfig is not loaded and could not be found

Upon inspecting the _build/prod/rel/a/lib directory, I noticed that the b dependency is missing.

What is the correct way to add project B as a dependency to project A for this specific use case? I would appreciate any advice or suggestions.

Marked As Solved

jchrist

jchrist

I think an included application does what you describe. Roughly, in project A’s mix.exs, you want to set runtime: false for the dependency to B, then update your application config:

  def application do
    [
      mod: {A.Application, []},
      included_applications: [:b],
      extra_applications: [:c, :d] # dependencies of :b that must be started for it to work
    ]
  end

The release will then include :b but not automatically start it. Note that if you have :b as a dependency elsewhere, that may cause it to start regardless - you need to add runtime: false there as well, in that case.
Hope that helps :slightly_smiling_face:

Also Liked

ycherniavskyi

ycherniavskyi

That worked brilliantly! :slight_smile:

I updated deps as follows:

  defp deps do
    [
      # ...
      {:a, github: "c/a", branch: "main", runtime: false}
    ]
  end

and application by:

  def application do
    [
      mod: {A.Application, []},
      included_applications: [:b],
      extra_applications: [:logger, :runtime_tools, :os_mon]
    ]
  end

In my case, I didn’t need to add anything to extra_applications because I was only using one simple module from B , which didn’t require any additional applications.

Where Next?

Popular in Questions Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New

We're in Beta

About us Mission Statement