I am using SBT as my build tool for building a Scala project.
My problem is, I can't configure SBT to download dependencies to my user home directory. Therefore I am looking for a per-user or even better a system-wide setting to tell SBT to put the Ivy cache directory somewhere else.
With maven there is the per-user settings.xml that can be used to configure the local repository.
I have read question How to override the location of Ivy’s Cache? and it's answers, but it seems it only describes how to configure the setting on a per project basis.
If there is no alternative I would go for a per-project setting, but I didn't get the answer from the mentioned question to work. Some more details would be most welcome, for example where to put the ivysettings.xml. I put it into the project's root directory and it didn't work.
For editing the cache location during the SBT boot itself, see Sbt Launcher Configuration in the official documentation.
Basically, to get it to work system-wide, you'd have to:
sbt.boot.properties
somewhere where it's accessible system-wide (the default one is listed at the link above).sbt.boot.properties
set to point to your configuration file.cache-directory
entry (in the[ivy]
section) to the location of your ivy cache.This configuration doesn't seem to carry over to normal SBT usage, though, unfortunately.
You can retrieve your home directory using
Path.userHome.absolutePath
, like shown below:I suppose that you can also retrieve environment variables using
System.getenv
and concatenate in the same way, like shown below:Location of ivy files
I normally put the ivy.xml and ivysettings.xml files alongside by build file as follows:
The ivy tasks resolve and retrieve should find both files.
For example:
Odd, that it's not working for you.
User specific settings
You can emulate the maven settings file in a couple of ways
1) include directive within the project ivysettings.xml
2) Set location from the build file
3) I've never tried this but I think you can override the default location using an ANT property
You can simply add an environment variable to your sbt launch shell script:
See Library Management in the official documentation.
You should use sbt-extras if you don't do already.
Then, it's simply a flag you pass it:
The
sbt.ivy.home
property is only half of the solution. It controls where the sbt launcher downloads sbt itself (and related dependencies like the scala compiler and library, etc.) As noted by Joachim Hofer, it has no effect on where the dependencies declared by your project get downloaded.To change that location, you must set the
ivy.home
property. So, to augment Joachim's first solution, you would set both system properties:With these properties, the launcher will download both your project's and sbt's dependencies to the
/tmp/.ivy2/
directory. Of course, you can put them in separate directories as well.