Skip to content

Instantly share code, notes, and snippets.

@vrischmann
Last active January 20, 2023 11:57
Show Gist options
  • Star 40 You must be signed in to star a gist
  • Fork 13 You must be signed in to fork a gist
  • Save vrischmann/9970819 to your computer and use it in GitHub Desktop.
Save vrischmann/9970819 to your computer and use it in GitHub Desktop.
Running SBT with a Nexus proxy with authentication
realm=Sonatype Nexus Repository Manager
host=nexus.company.com
user=admin
password=admin123
export SBT_CREDENTIALS="$HOME/.ivy2/.credentials"
export SBT_OPTS="-Dsbt.override.build.repos=true -Dfile.encoding=UTF8 -Xms1024m -Xmx1024m -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m"

WARNING Not tested with the sbt script from the Debian package, if you use it be sure to check the .sbtconfig is correctly imported.

Instructions

  • Put .sbtconfig in $HOME/.sbtconfig
  • Put credentials.sbt in $HOME/.sbt/0.13/plugins/credentials.sbt
  • Put .credentials in $HOME/.ivy2/.credentials
  • Put repositoriesin $HOME/.sbt/repositories

Nexus configuration

On your Nexus instance, you need to create two "Repository Groups", one called ivy and one called maven. The ivy one should include these two repositories:

The maven one should include at least the Maven Central repository, already configured in Nexus by default. You can add in this group any other repository you want, like the Aapche Snapshots repository or whatever.

credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")
[repositories]
local
my-ivy-proxy-releases: http://nexus.company.com/nexus/content/groups/ivy/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
my-maven-proxy-releases: http://nexus.company.com/nexus/content/groups/maven/
@jatcwang
Copy link

Note that the SBT launcher (which resolves your SBT plugins) currently doesn't load credentials correctly. See the issue here: sbt/sbt#576

You can specify credentials by passing in system properties sbt.boot.{realm, host, user, password}. However SBT currently has a bug parsing system properties as it splits naively on spaces, so if your realm has a space in it (the default Nexus realm does) then it'll break.
See this issue: sbt/sbt#2787

@yaniveliash
Copy link

Nexus doesn't resolve any ivy release plugin (e.g. sbt-assembly)

@javigs82
Copy link

javigs82 commented May 8, 2018

This solution works perfect.
Just to improve it, .sbtconfig is deprecated, does nothing

@tindzk
Copy link

tindzk commented Jun 15, 2018

@javigs82: .sbtopts can be used instead of .sbtconfig (see also this article).

Also, if you do not want to configure the proxy globally, you can add the following lines to .sbtopts:

-Dsbt.override.build.repos=true
-Dsbt.repository.config=project/repositories  # Custom path to repository configuration

@vrischmann
Copy link
Author

While doing some cleanup I realized that other people actually used this. I've not used sbt for a least 3 years so it's completely possible it no longer works.

If someone ends up here and notices something wrong you can ping me and I'll amend the gist.

Copy link

ghost commented Aug 19, 2020

What repository type should I choose on Nexus since Ivy is not an option? Or is it just not an option in Nexus OSS?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment