I've got an sbt (Scala) project that currently pulls artifacts from the web. We'd like to move towards a corporate-standardized Nexus repository that would cache artifacts. From the Nexus documentation, I understand how to do that for Maven projects. But sbt obviously uses a different approach. (I understand Ivy is involved somehow, but I've never used it and don't understand how it works.)

How do I tell sbt and/or the underlying Ivy to use the corporate Nexus repository system for all dependencies? I'd like the answer to use some sort of project-level configuration file, so that new clones of our source repository will automatically use the proxy. (I.e., mucking about with per-user config files in a dot-directory is not viable.)

@VonC I did some bulk update of questions with the [maven] tag and thought this one was more about Nexus than Maven(-2). But if you think it's relevant, feel free to rollback/update accordingly, I went maybe too fast on this one.
–
Pascal ThiventSep 22 '10 at 19:45

yeah, maven is maybe not the primary tag, but it's certainly about maven repos. I rolled it back.
–
HarlanSep 22 '10 at 19:50

By the way, it is confirmed: it works as advertised, both at home and at work. I have edited my question to illustrate that, and to add some repository definitions for you to examine.
–
VonCSep 25 '10 at 15:20

(If you are using Artifactory, you can skip this step.) Create an entirely separate Maven proxy repository (or group) on your corporate Maven repository, to proxy ivy-style repositories such as these two important ones:

Either save that file in the .sbt directory inside your home directory, or specify it on the sbt command line:

sbt -Dsbt.repository.config=<path-to-your-repo-file>

Good news for those using older versions of sbt: Even though, in the sbt 0.12.0 launcher jar at least, the boot properties files for older sbt versions don't contain the required line (the one that mentions repository.config), it will still work for those versions of sbt if you edit those files to add the required line, and repackage them into the sbt 0.12.0 launcher jar! This is because the feature is implemented in the launcher, not in sbt itself. And the sbt 0.12.0 launcher is claimed to be able to launch all versions of sbt, right back to 0.7!

Step 2: To make sure external repositories are not being used, remove the default repositories from your resolvers. This can be done in one of two ways:

Add the command line option -Dsbt.override.build.repos=true mentioned on the Detailed Topics page above. This will cause the repositories you specified in the file to override any repositories specified in any of your sbt files. This might only work in sbt 0.12 and above, though - I haven't tried it yet.

Use fullResolvers := Seq(resolver(s) for your corporate maven repositories) in your build files, instead of resolvers ++= or resolvers := or whatever you used to use.

I'm using Scala 2.10, Artifactory 3, sbt 12.3 and having no luck using the directions here and in the docs referenced herein. I know its reading repositories after finding a typeo there. I've set the property on the launcher via -D. SBT is acting like its not disregarding the default resolvers as it says it should with -Dsbt.override.build.repos=true. I could try point 2 above, but it sounds like it should not be neccessary?
–
TotoroMay 14 '13 at 16:24

@Robin Green: thanks so much, this problem was driving me crazy and your solution worked for me.
–
GrundlefleckSep 16 '13 at 13:13

Thanks for the extremely complete response! But it's not working for me. I've created an sbt.boot.properties file, and it only has three repositories listed: local, maven-local, and my-nexus which points to our local Nexus repo. sbt is a script with the following: java -Xmx1024M -Dsbt.boot.properties="sbt.boot.properties" -jar dirname $0/sbt-launch.jar "$@" If I then delete a package (say, Squeryl) from my .ivy2 cache, then do "sbt update", it appears to be pulling from the public internet, without touching our Nexus install. How/why?
–
HarlanSep 23 '10 at 14:40

@Harlan: Why? because it doesn't take into your account your sbt.boot.properties. Did you create it just beside sbt-launch-0.7.4.jar (meaning in your classpath)? Come to think of it, I don't see any classpath explicitly defined in your java command.
–
VonCSep 23 '10 at 15:03

It's definitely loading sbt.boot.properties. With the command I showed above, if I change the Scala version to 2.9.7 in that file, it vainly tries to get 2.9.7. So it's not a classpath problem. But sbt update is pulling from scala-tools.org even if only local and my-nexus are defined.
–
HarlanSep 23 '10 at 16:20

@Harlan: did you try to define no repositories? Or to define something obviously false? I still have a hard time believing your specific property file is taken into account.
–
VonCSep 23 '10 at 17:14

This is weird. If I set scala version to 2.9.7, and comment out all repositories, then it gripes "Error during sbt execution: No repositories defined." But if I set scala version to 2.7.7, and comment out all repositories, it gripes and seemingly ignores the repository list!
–
HarlanSep 23 '10 at 17:50

Well this has bugged me for a while so I found a guy that has written an SBT plugin for maven out on github called maven-sbt so all you have to do is include it in your plugins project and make your project mixin with maven.MavenDependencies and all your operations like update and publish-local work with your local maven. The nice thing about that is if you are like me, your org is all maven. So, all you libs are in you local maven repo but if for some reason you build with sbt first, then you start getting a bunch or jars in ivy too. What a waste of space, and time since you will still need to get them for your maven builds.

That said, I wish this were built into sbt so I would not need to add it to every project. Maybe as a processor at least. He mentioned in one thing I read that he would like to add it to 0.9 but I have not been able to find it.