How to prevent SBT from trying to download from of

2020-06-16 11:16发布

问题:

I want to use SBT with IntelliJ IDEA 14.1. However, I want to download everything from our company-internal Nexus server. I made two repository groups there which contain some proxy repositories.

My .sbt/repositories file looks like this:

[repositories]
  local
  my-ivy-proxy-releases: http://our-nexus/nexus/content/groups/sbt_ivy_group/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
  my-maven-proxy-releases: http://our-nexus/nexus/content/groups/public/

The URLs are fine, I can open them in my browser.

Now, when I run sbt either from command line or from IntelliJ IDEA, it tries to download from repo.scala-sbt.org, repo.typesafe.com etc. even though I do not want it.

How do I force SBT to only download from the repositories in the repositories file?

EDIT: It does download from our company nexus, but only after trying the "official" releases, which result in loads of "connection refused" because we are behind an HTTP proxy which slows dependency resolving down quite a lot.

EDIT 2: I tried to add -Dsbt.override.build.repos=true to the VM parameters of IDEA's SBT settings, but this does not seem to change anything.

回答1:

The best way is to override default repositories: from help in sbt and also here

Override default resolvers

resolvers configures additional, inline user resolvers. By default, sbt combines these resolvers with default repositories (Maven Central and the local Ivy repository) to form externalResolvers. To have more control over repositories, set externalResolvers directly. To only specify repositories in addition to the usual defaults, configure resolvers.

For example, to use the Sonatype OSS Snapshots repository in addition to the default repositories,

resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"

To use the local repository, but not the Maven Central repository:

externalResolvers :=
  Resolver.combineDefaultResolvers(resolvers.value.toVector, mavenCentral = false)

Override all resolvers for all builds

The repositories used to retrieve sbt, Scala, plugins, and application dependencies can be configured globally and declared to override the resolvers configured in a build or plugin definition. There are two parts:

Define the repositories used by the launcher.
Specify that these repositories should override those in build definitions.

The repositories used by the launcher can be overridden by defining ~/.sbt/repositories, which must contain a [repositories] section with the same format as the Launcher Specification configuration file. For example:

[repositories]
local
my-maven-repo: http://example.org/repo
my-ivy-repo: http://example.org/ivy-repo/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]

A different location for the repositories file may be specified by the sbt.repository.config system property in the sbt startup script. The final step is to set sbt.override.build.repos to true to use these repositories for dependency resolution and retrieval.



标签: scala sbt