Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Importing modules when not using mix

I’m experimenting with Elixir as a CI script language in GitHub actions. Wondering if there is a straight-forward way to import dependencies when not using mix:

      - uses: erlef/setup-beam@v1
        with:
          otp-version: ${{ env.OTP_VERSION }}
          elixir-version: ${{ env.ELIXIR_VERSION }}

      - id: main
        run: |
          defmodule DoStuff do
            import JSON   # Doesn't work
          end
        shell: elixir -r {0}

Including a mix project in the repository seems a little overkill for simple scripts. Is there an easy way to do get modules when running standalone scripts through elixir -r?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Mix.install/2 is your friend.

CODE='Mix.install([{:jason, "~> 1.0"}])
quote> defmodule M, do: import Jason'

❯ elixir -e $CODE
Resolving Hex dependencies...
Dependency resolution completed:
New:
  jason 1.3.0
* Getting jason (Hex package)
==> jason
Compiling 10 files (.ex)
Generated jason app
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading