Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sbt 0.11: Using a corporate maven repository

Tags:

maven

sbt

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.

like image 785
Robin Green Avatar asked Feb 02 '12 15:02

Robin Green


2 Answers

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:

    • http://repo.typesafe.com/typesafe/ivy-releases/
    • http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/

    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).

like image 56
Robin Green Avatar answered Sep 17 '22 22:09

Robin Green


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.

like image 27
Ajay Chandran Avatar answered Sep 21 '22 22:09

Ajay Chandran