本文介绍了如何防止 SBT 尝试从官方存储库下载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想在 IntelliJ IDEA 14.1 中使用 SBT.但是,我想从我们公司内部的 Nexus 服务器下载所有内容.我在那里创建了两个存储库组,其中包含一些代理存储库.

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.

我的 .sbt/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.

现在,当我从命令行或 IntelliJ IDEA 运行 sbt 时,它会尝试从 repo.scala-sbt.org、repo.typesafe.com 等下载,即使我没有想要.

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.

如何强制 SBT 仅从存储库文件中的存储库下载?

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

确实从我们公司的 nexus 下载,但只有在尝试官方"版本之后,导致大量连接被拒绝",因为我们落后了一个 HTTP 代理,它大大减慢了依赖解析的速度.

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:我尝试将 -Dsbt.override.build.repos=true 添加到 IDEA 的 SBT 设置的 VM 参数中,但这似乎没有改变任何东西.

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.

推荐答案

最好的方法是覆盖默认存储库:来自 帮助 sbt 以及 这里

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

覆盖默认解析器

resolvers 配置额外的内联用户解析器.默认情况下,sbt 将这些解析器与默认存储库(Maven Central 和本地 Ivy 存储库)组合以形成 externalResolvers.要更好地控制存储库,请直接设置 externalResolvers.除了通常的默认值之外,要仅指定存储库,请配置 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.

例如,要在默认存储库之外使用 Sonatype OSS Snapshots 存储库,

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"

要使用本地存储库,但不使用 Maven 中央存储库:

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

用于检索 sbt、Scala、插件和应用程序依赖项的存储库可以全局配置并声明为覆盖构建或插件定义中配置的解析器.分为两部分:

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.

可以通过定义 ~/.sbt/repositories 来覆盖启动器使用的存储库,其中必须包含一个与启动器规范配置文件格式相同的 [repositories] 部分.例如:

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]

存储库文件的不同位置可以由 sbt 启动脚本中的 sbt.repository.config 系统属性指定.最后一步是将 sbt.override.build.repos 设置为 true 以使用这些存储库进行依赖项解析和检索.

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.

这篇关于如何防止 SBT 尝试从官方存储库下载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 22:04