Skip to content

Instantly share code, notes, and snippets.

@teliatko
Last active October 14, 2021 10:42
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teliatko/127f4ec7e5362f1f5cc68ade9f1221ac to your computer and use it in GitHub Desktop.
Save teliatko/127f4ec7e5362f1f5cc68ade9f1221ac to your computer and use it in GitHub Desktop.
Setting up the Ivy home for sbt and Intellij IDEA

Setting up Ivy home for SBT

One can set adhoc Ivy home for SBT as:

# Using example directory in tmp
$ sbt -ivy /tmp/.ivy2

# Another option
$ sbt -Dsbt.ivy.home=/tmp/.ivy2/

When you use directory under ~/ (i.e. home directory) th expansion in 2nd variant will not work, i.e:

# Expansion of `~/` to home directory will not work
$ sbt -Dsbt.ivy.home=~/.ivy2-branch

You have to use $HOME environment variable to make it work instead as:

# This is OK
$ sbt -Dsbt.ivy.home=$HOME/.ivy2-branch

Maybe this is bug in SBT launcher scripts, but expansion to $HOME works, but ~/ doesn't. When using ~/ the ~ directory is created in the root of project. The Ivy home resides then under that directory.

Setting up Ivy home for IntelliJ IDEA

Another round of issues comes up when you try to configure different Ivy home in IntelliJ IDEA (assuming that Scala Plugin is installed). In window Preferences > Build,Execution,Deployment > Build Tools > SBT you can configure JVM parameters which are taken into account when SBT is run. There is no possibility to configure -ivy CLI option directly in IDEA.

Using absolute paths is without issues, hence typing -Dsbt.ivy.home=/tmp/.ivy2/ in VM parameters field will do the magic. But ... when you are trying to use user home as $HOME or ~/ things will not work. Referring ~/ will cause the same behavior as by running SBT from command line. Using $HOME will be not expanded too.

There is an option to use $USER_HOME$, which is IDEA Path Variable. Thus using -Dsbt.ivy.home=$USER_HOME$/.ivy2-branch/ in VM parameters form field will work.

Yet another option is to directly edit .idea/sbt.xml file in current project directory adding the line in bold (after maximumHeapSize)`:

  <option name="maximumHeapSize" value="4096" />
  <option name="vmParameters" value="-Dsbt.ivy.home=$USER_HOME$/.ivy2-branch" />

Described behavior relates to SBT version 0.13.11 and IntelliJ IDEA v 2016.1.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment