Access project version within elixir application

I have an elixir project with a defined version. How can I access this from within the running application.

in mix.exs

  def project do
    [app: :my_app,
     version: "0.0.1"]
  end

I would like to be access this version number in the application so I can add it to the returned message. I looking for something in the env hash like the following

__ENV__.version
# => 0.0.1

Here's a similar approach to retrieve the version string. It also relies on the :application module, but is maybe a bit more straightforward:

{:ok, vsn} = :application.get_key(:my_app, :vsn)
List.to_string(vsn)

otp - Access project version within elixir application, Here's a similar approach to retrieve the version string. It also relies on the : application module, but is maybe a bit more straightforward: {:ok, vsn}� I have an elixir project with a defined version. How can I access this from within the running application. in mix.exs. def project do [app: :my_app, version: "0.0.1"] end I would like to be access this version number in the application so I can add it to the returned message. I looking for something in the env hash like the following

Mix.Project itself provides access to all project keywords defined in mix.exs using its config/0 (api doc) function. For concise access it might be wrapped into a function:

@version Mix.Project.config[:version]
def version(), do: @version

Application version on Phoenix - Questions / Help, Is there an elegant way to access to the application version? Project.config()[: version] def version(conn, _param) do text conn, @version end. An open-source e-commerce platform in elixir. This project should be used if you want to start your own e-commerce store. Admin panel and store front are the 2 main offerings in the platform.

In recent versions of Elixir, the Application module now wraps this for you:

https://github.com/elixir-lang/elixir/blob/master/lib/elixir/lib/application.ex

Application.spec(:my_app, :vsn) |> to_string()

The Kernel.to_string() method is necessary as Application.spec/2 for the keys :vsn and :description return charlists. to_string() from the Kernel module converts them to a binary.

Best approach to do auto versioning of an elixir application phoenix , I have an elixir project with a defined version. How can I access this from within the running application. in mix.exs def project do [app: :my_app, version: "0.0.1"] � However, instead of adding more code to the kv application, we are going to build the TCP server as another application that is a client of the kv application. Since the whole runtime and Elixir ecosystem are geared towards applications, it makes sense to break our projects into smaller applications that work together rather than building a big, monolithic app.

I found the version inside of :application.which_applications, but it requires some parsing:

defmodule AppHelper do
  @spec app_version(atom) :: {integer, integer, integer}
  def app_version(target_app) do
    :application.which_applications
    |> Enum.filter(fn({app, _, _}) ->
                    app == target_app
                   end)
    |> get_app_vsn
  end

  # I use a sensible fallback when we can't find the app,
  # you could omit the first signature and just crash when the app DNE.
  defp get_app_vsn([]), do: {0,0,0} 
  defp get_app_vsn([{_app, _desc, vsn}]) do
    [maj, min, rev] = vsn
                      |> List.to_string
                      |> String.split(".")
                      |> Enum.map(&String.to_integer/1)
    {maj, min, rev}
  end
end

And then for usage:

iex(1)> AppHelper.app_version(:logger)
{1, 0, 5}

As always, there's probably a better way.

Introduction to Mix, In this guide, we will learn how to build a complete Elixir application, with its own project , which returns project configuration like the project name and version, done by accessing the Mix.env function in your mix.exs file, which returns the� After opening the Project Online Desktop Client, at the login screen, for Profile select Computer, and then select OK. On the next screen, select Blank project. On the new project page, select the File menu. On the Backstage menu, select Info, and then select Manage Accounts. On the Project Web Apps Accounts page, select Add. On the Account Properties page:

What about :

YourApp.Mixfile.project[:version]

Dependencies and umbrella projects, This dependency refers to the latest version of Plug in the 1. Umbrella projects are used to build applications that run together in a single repository. as any other dependency or even Elixir itself: you can only access what is public and� I will be using Elixir 1.5 in this article (it was released a couple of months ago), but all the explained concepts should apply to version 1.4 as well. Applications? Some might argue that the term "application" is not very appropriate because in Erlang and Elixir it actually means a component, or some code that has a bunch of dependencies.

Mix.Project — Mix v1.10.4, Project def project do [ app: :my_app, version: "1.0.0" ] end end a project to be defined or needs to access a special function within the project, Elixir or Mix. What is an Elixir Umbrella application? code up into smaller applications that can be organised logically within a single project. This is where Umbrella projects come into play, an Elixir

mix release — Mix v1.10.4, Assembles a self-contained release for the current project: Releases do not even require Erlang or Elixir in your servers, as it includes the Erlang VM and its runtime by default. Defaults to the current application version. It MUST NOT access Mix in any way, as Mix is a build tool and it not available inside releases. Developers building applications using Elixir are fortunate to have ETS available as part of the Erlang VM toolbelt. ETS provides a right mix of simplicity (removing the need for integrating yet another tool to a project) with performance (it’s a fast and battle-tested piece of software).

Getting elixir app version from command line, harder than they have to be. Here is how to get the app version defined in mix. exs from your terminal with mix. Getting elixir app version from command line. published 24 Project.config[:version] end end. Now you can�

Comments
  • This is a better way. Personally, I'd still use the charlist |> string |> integer parsing pipeline, but this is definitely cleaner than using which_applications.
  • Yes good point. Chris' solution is obviously longer because it does an extra step to convert the string into a tuple of integers. Just for printing, the plain string should however be enough. You could combine the two answers to get the tuple if you need it.
  • Make sure this is evaluated at compile time like shown in the example. Otherwise it will not work in production because module Mix.Project is not available.
  • Good answer cheers. Though kinda a shame if that is the best way to get at it.
  • That's the guidance that Jose Valim gave to someone just a few weeks ago. That is, use :application.which_application. groups.google.com/d/msg/elixir-lang-talk/qlX4hJKZvC8/…
  • Just FYI, that's a canned comment inserted automatically during review - it really doesn't reflect this case, which is unfortunate. My own take on it: An answer is a statement, ideally backed up with authoritative references, examples, and/or experiences. Although there is no question mark here, "What about..." is a question. If this is indeed an answer, I suggest you edit it to sound like one, and offer a brief explanation that would educate readers by connecting the proffered solution to the problem.