···
15
-
By reading this article I assume that you already have written some Elixir code.
16
-
Even if you haven't (yet) then I think that you can find it interesting as
17
-
a story how BEAM handles it's applications. But back on topic, when you start
18
-
your new Elixir project via `mix new my_awesome_project` you will end with
19
-
something like this in `mix.exs`:
15
+
When you start your new Elixir project via `mix new my_awesome_project` you will
16
+
end with something like this in `mix.exs`:
defmodule MyAwesomeProject.Mixfile do
···
And in most cases you will focus on `deps/0`, sometimes on `config/0`, but the
48
-
`application/0` you will almost never touch, and if you do you probably only
45
+
`application/0` you will almost never touch, and if you do, you probably will only
need it to add new entry in `:extra_applications` or sometimes
50
-
`:included_applications`. Except that this function interns are almost terra
51
-
incognita, place where you never look unless you are forced to, just like "Read
52
-
it later" list in Safari. And that is sad, as this is quite powerful and useful
53
-
piece of code, that hides really useful stuff.
47
+
`:included_applications`. Except for, that this function interns are terra
48
+
incognita, a place where you never look unless you are forced to, like "Read
49
+
it later" list in Safari. This is sad, as it is quite powerful and useful
## What `application/0` is for?
59
-
In Erlang the running system is built from applications. These applications are
60
-
like processes in your system that are managed by your system supervisor (SysV,
61
-
systemd, OpenRC, launchd, etc.) and are launched either during VM startup or on
62
-
direct user request via `Application.start/1-2` and it's family. How to start
63
-
such application is described in `my_awesome_app.app` file which is commonly
56
+
In Erlang the running system is built from applications. Those applications are
57
+
like processes in your system managed by your system supervisor (SysV, systemd,
58
+
OpenRC, launchd, etc.). They are launched either during VM startup or on
59
+
direct user request via `Application.start/1-2` and its family. Starting
60
+
this application is described in `my_awesome_app.app` file which is commonly
generated by the build system from the template. In Rebar3 projects this
template is `src/appname.app.src` and in Elixir it's the return value of the
named `application/0` function. This generated file is known as [Application
67
-
Resource File][app file] and is just tuple in form of `{:application,
64
+
Resource File][app file]. It is just tuple in form of `{:application,
:my_awesome_app, opts}` where `opts` is a keyword list of additional properties
(to be exact it's output of the `application/0` function).
71
-
Two of these optional fields are quite known in the Elixir community:
68
+
Two of those optional fields are quite known in the Elixir community:
73
-
- `:mod` which is a tuple `{module(), term()}` which contain the starting point
74
-
of our application, in most cases it's module that will return main
70
+
- `:mod` which is a tuple `{module(), term()}` containing the starting point
71
+
of our application; in most cases this is the module that will return main
supervisor of the application.
76
-
- `:applications` which contain all applications that are required by our
77
-
application. Younger Elixir developers possibly never seen that as since 1.5
78
-
this field is automatically filled by parsing `:deps`, we still can add
79
-
entries there though via `:extra_applications`.
73
+
- `:applications` contains all applications required by our application; younger
74
+
Elixir developers possibly never seen that as since version 1.5 this field
75
+
is automatically filled by parsing `:deps`, though we still can add entries
76
+
there via `:extra_applications`
81
-
There are also few Elixir specific fields, that are sometimes used in bigger
78
+
There are also few Elixir specific fields, sometimes used in larger projects:
84
-
- `:extra_applications` - applications that should be included in the release
85
-
and automatically started before running this application but aren't in the
80
+
- `:extra_applications` - those should be included in the release
81
+
and automatically started before running current application; but aren't in the
dependencies list because, for example, are in default distribution, for
example `logger` or `inets`.
88
-
- `:included_applications` - applications that should be included in the
84
+
- `:included_applications` - applications which should be included in the
release, but not automatically started on boot.