9

How can a corporate Maven repository be used (to the exclusion of other repositories) with sbt 0.11.x, as described in how do I get sbt to use a local maven proxy repository (Nexus)? ? There is no mention of ivyRepositories in the new sbt wiki at github, so I'm assuming the accepted solution there is out of date.

Community
  • 1
  • 1
Robin Green
  • 29,408
  • 13
  • 94
  • 178

3 Answers3

11

Step 1: Follow the instructions at Detailed Topics: Proxy Repositories, which I have summarised and added to below:

  1. (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.

  2. 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:

    [repositories]
      my-maven-proxy-releases: http://repo.example.com/maven-releases/
      my-ivy-proxy-releases: http://repo.example.com/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
    
  3. Either save that file in the .sbt directory inside your home directory, or specify it on the sbt command line (you will need to specify if you have disabled sharing):

    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 three ways:

  1. 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.
  2. Having the same effect as 1, you can use overrideBuildResolvers := true, with the advantage that you can control the projects where it is applicable, depending on which scope (a project / ThisBuild / Global) you define it in. This works in sbt 0.13.
  3. 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.

Finally, note that the sbt launcher script has a bug in reading the sbtopts file, so if you decide to put your common sbt command-line options in there, make sure the last line of the file ends in a newline (Emacs in particular can fail to ensure this, unless configured to do so).

Community
  • 1
  • 1
Robin Green
  • 29,408
  • 13
  • 94
  • 178
  • I tried to use option 2 of step 2 setting overrideBuildResolvers := true in build.sbt but this did not work for me. Is there anything to pay special attention to when setting this? – Ronald May 20 '15 at 12:25
  • When using Windows, please note that sbt -Dsbt.override.build.repos=true will give you a warning and the flag is ignored. You should use -D"sbt.override.build.repos=true", I believe that double quotes are needed due to some cmd magic. – Ameba Spugnosa Aug 10 '16 at 07:24
5

An alternative for Step 2 of the accepted answer (am using sbt 0.13.1):

Add file .sbtopts to the project root directory with contents:

-Dsbt.override.build.repos=true

Another alternative is to add this line in $SBT_HOME/conf/.sbtopts, but this would force the setting for all projects.

Bohemian
  • 365,064
  • 84
  • 522
  • 658
Ajay Chandran
  • 51
  • 1
  • 1
  • You might also use this in step 1 and put the `-Dsbt.repository.config=` config in it. This way, the complete repo configuration can be set on a per-project basis and added to the code repository. – F30 Mar 31 '17 at 17:15
3

Unpack the sbt-launcher.jar and copy the sbt.boot.properties file to a location of your choice. Change the launch script to use this file. In the file, change the repositories section to only contain your local repo and the corporate one. The distinction between Maven and Ivy comes from the given pattern (no pattern means Maven pattern by default).

Here is an example:

[repositories]
  local
  corporate: http://inhouse.acme.com/releases/
Heiko Seeberger
  • 3,648
  • 19
  • 20
  • I tried this, but it didn't work. It didn't even try the corporate repository at all! Maybe there is some confusion here. I want the corporate repository to be used by default, without having to specify it in `build.sbt`. – Robin Green Feb 07 '12 at 15:54
  • 1
    No confusion, @HeikoSeeberger 's answer should do exactly what you're asking: substitute your corporate repository for Maven central. If it's not working for you, sbt probably isn't picking up your modified `sbt.boot.properties` file. As noted, you have to modify your sbt launch script to tell sbt to use the modified file: java -Dsbt.boot.properties=sbt.boot.properties -jar `dirname $0`/sbt-launch-0.11.2.jar "$@" (Assuming you put the modified `sbt.boot.properties` in the same directory as sbt itself.) – Mark Tye Feb 07 '12 at 21:43
  • I also tried it, but doesn't work. It definitely reads my custom sbt.boot.properties, because if I put a syntax typo, sbt won't load. And if I delete all repositories, sbt won't resolve needed artifact. However, when the artifact is already in the Nexus repo and sbt.boot.properties is configured, sbt still won't get it! – Hendy Irawan Feb 26 '12 at 20:01
  • I can confirm that in sbt 0.11.2, editing the repositories from sbt.boot.properties has NO effect at all, with this command: show external-resolvers – Hendy Irawan Feb 26 '12 at 20:25
  • Maybe you are configuring your resolvers in your build the wrong way? Are you adding to the resolvers or just setting some values? I.e. are you using the += or ++= operators? – Heiko Seeberger Feb 27 '12 at 08:57