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.)
Thanks!
OK, with some help from Mark Harrah on the sbt mailing list, I have an answer that works.
My build class now looks like the following (plus some other repos):
Now, if I delete the Squeryl tree from my machine's
.ivy2/cache
directory, sbt tries to grab it from the Nexus tree with the appropriate URL. Problem solved!All you need is to define a property file
sbt.boot.properties
which will allow you to:Note: this
sbt.boot.properties
file is inspired from:sbt-0.74
itself!I have commented any external Maven repository definition, and added a reference to my own Nexus Maven repo.
Define a sbt.bat wrapper (in order to be sure to specify your
sbt.boot.properties
) like:And your sbt will download artifacts only from:
Just tested at home with an old Nexus opensource 1.6 I had running, java 1.6, sbt07.4
That gives:
If I try a funny value in the sbt.boot.properties file:
So it does limit itself to the two repo I defined:
(I commented everything else:
local
,maven-local
, ...)If I comment all repositories and put a funny value (2.7.9) for the scala version in the
sbt.boot.properties
, I do get (like the OP did)If I put 2.7.7 (while still having all repo commented), yes, it won't generate an error:
But that's only because it already had downloaded scala2.8.0 during my previous tries.
If I remove that library from my
project/boot
directory, then it will throw an Exception:edit the config file in sbt_home/conf "sbtconfig.txt"
add two line
the repo.properties content is
Step 1: Follow the instructions at Detailed Topics: Proxy Repositories, which I have summarised and added to below:
(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:
This is needed because some repository managers cannot handle Ivy-style and Maven-style repositories being mixed together.
Create a file
repositories
, listing both your main corporate repository and any extra one that you created in step 1, in the format shown below:Either save that file in the
.sbt
directory inside your home directory, or specify it on the sbt command line: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:
-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.fullResolvers := Seq(
resolver(s) for your corporate maven repositories)
in your build files, instead ofresolvers ++=
orresolvers :=
or whatever you used to use.I got this error because I had a blank file in
~/.sbt/repositories
. Both adding repositories to the file and removing the file solved the problem.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.