views:

217

answers:

2

I am using SBT as my build tool for building a Scala project.

My problem is, I can't let SBT download its 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.

A: 

Location of ivy files

I normally put the ivy.xml and ivysettings.xml files alongside by build file as follows:

build.xml
ivy.xml
ivysettings.xml

The ivy tasks resolve and retrieve should find both files.

For example:

<target name="init" description="--> retrieve dependencies with ivy">
    <ivy:retrieve pattern="lib/[conf]/[artifact].[ext]"/>
</target>

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

<ivysettings>
    <include file="${user.home}/.ivy2/my-ivysettings.xml"/>
</ivysettings>

2) Set location from the build file

<target name="init" description="--> retrieve dependencies with ivy">
    <ivy:settings file="${user.home}/.ivy2/my-ivysettings.xml" />
    <ivy:retrieve pattern="lib/[conf]/[artifact].[ext]"/>
</target>

3) I've never tried this but I think you can override the default location using an ANT property

ant -Divy.settings.file=$HOME/.ivy2/my-ivysettings.xml
Mark O'Connor
Thank you for your answer, but it seems to me you are assuming I am using Ant together with Ivy. Maybe it isn't clear from my question, but I am using SBT as my build tool, not Ant. I will edit my question accordingly.
Ruediger Keller
+2  A: 

I got only one thing to work, although it's more a hack than a solution: In your sbt launch shell script, change the "user.home" java system property...

Joachim Hofer
That's a good idea! I will try it and if it works, your answer will be the solution.
Ruediger Keller