Ammonite Support

Anton Yalyshev

Ammonite, developed by Li Haoyi, is a well-known toolset that lets us use Scala language for scripting purposes. It contains a modernized REPL, a replacement for the Bash system shell, a Filesystem Library, and specific notations for more productive scripting.
Even though many situations in which you would use Ammonite are intended for the command-line mode, quite a few use cases are also relevant for an IDE. After receiving some feedback from our users, we’ve decided to provide advanced support for this technology in our Scala plugin. The set of enhancements includes: support for Ammonite Notations, Run Configuration, a gutter icon for running scripts more easily, and pop-up actions for automatically importing libraries. Read on for more details and screenshots.
To demonstrate our new features, we’ll use an example of Li Haoyi’s project, which forms a blog from a set of text documents and pictures. As Ammonite is an external tool, there are some prerequisites for its usage:

  • Ammonite must be installed on your OS.
  • IntelliJ IDEA needs to knows where the Ammonite executable is located. You can:
    • add a symlink to already accessible places like usr/bin;
    • modify the $path variable; or
    • specify the path to the Ammonite executable in Default Ammonite Run Configuration, by using the “Amm executable” field.
  • Finally, .sc files have to be treated as Ammonite files (by default, IntelliJ IDEA treats them as Worksheets). You can define this in File | Settings | Languages & Frameworks | Scala | Worksheet.


Importing Libraries

After you’ve completed the above, IntelliJ IDEA suggests adding Ammonite standard dependencies to your project when you open an .sc file for the first time. This is required for code processing in the Editor and for navigation.
IntelliJ IDEA will download the latest version of Ammonite. Besides, if an opened file contains $ivy. imports, IntelliJ IDEA will suggest adding them to the project as well. Note that declared libraries have to be present in local caches. If they’re missing, just run the code with these imports once and Ammonite will automatically add them to the cache.
After these imports are done, you are all set and can successfully use IDE tools to work with Ammonite code. If you open a new project, IntelliJ IDEA will suggest performing these actions one by one, as new imports appear.

Ammonite Notations, Predefs and Builtins

The editor correctly handles all Ammonite-specific code and provides appropriate highlighting and navigation.

Launching Scripts

You can run your scripts right from the Editor by using the gutter icon to the left of the code that looks like a ‘play’ button. The Scala plugin will automatically create a Run Configuration and show the output of the script in the Run Tool Window:
We would love to learn more about your experiences with Ammonite and IntelliJ IDEA. Please share with us! Feature requests, pull requests and improvement suggestions are very welcome, too! Your feedback can influence the roadmap for Ammonite support a lot. Just add a comment here or create an issue in YouTrack. Thanks!

Happy developing!

Comments below can no longer be edited.

13 Responses to Ammonite Support

  1. Lachlan O’Dea says:

    May 7, 2018

    I’ve tried it and it’s very cool.

    The big issue I hit is when I add the $ivy imports to the project, it only adds the libraries explicitly imported, not their dependencies. In practice I had to add the libraries manually via the “add from Maven” feature so IntelliJ knew about all the dependencies.

  2. gcsocial says:

    May 11, 2018

    specify the path to the Ammonite executable in Default Ammonite Run Configuration, by using the “Amm executable” field. Is this in IntelliJ? I don’t see this field in IntelliJ.

  3. Jeff says:

    May 15, 2018

    I am running #2018.1.9, but it never prompts me for ammonite imports, just ivy imports, which work fine, by either clicking the link, or doing alt->return and choosing create library from package (or similar).

    Would love to get the ammonite packages included. Intellij knows where my binary is (as its in the base path), worksheets->Always Ammonite is configured correctly

    Thanks if anyone has the special sauce to work around this, I’d love to hear it. Thanks for the plugin!!

  4. Dyno Fu says:

    September 6, 2018

    if I want my script to install a package from a private maven repository, how to add the repository to Intellij so that it can find the package?

  5. Alex Berg says:

    October 5, 2018

    I have added some trouble-shooting info here on stack overflow (arberg):

    The IntelliJ ‘add’ buttons fails silently in different situations such as
    * Scala/JDK isn’t yet loaded in project
    * No Ammonite release exists for the given scala version. At the time of writing the current stable Ammonite release 1.2.1 is not released for Scala 2.12.7

  6. Stian Lågstad says:

    October 23, 2018

    Is there a way to debug .sc scripts when recognized as ammonite scripts? I’d like to use the IntelliJ debugger as I normally do, with breakpoints and evaluations.

  7. david perez says:

    November 6, 2018

    How to force IDEA to reprocess the $ivy imports that my script contains

  8. david perez says:

    November 6, 2018

    How to force IDEA to reprocess the $ivy imports that my script contains?

  9. Janbo says:

    March 16, 2019

    Is there any way to run this on Windows 10

  10. Leonid Ilyevsky says:

    October 2, 2019

    One minor but annoying issue: when I use the build dependencies import in the mill build script, the imported package definition between the back quotes is highlighted red.

    For example:


    The error says “Cannot resolve symbol `com.typesafe:config:1.3.4`”.