如何让 sbt 使用本地 Maven 代理存储库(Nexus)? [英] how do I get sbt to use a local maven proxy repository (Nexus)?

查看:64
本文介绍了如何让 sbt 使用本地 Maven 代理存储库(Nexus)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 sbt (Scala) 项目,该项目目前从网络中提取工件.我们希望转向可以缓存工件的企业标准化 Nexus 存储库.从 Nexus 文档中,我了解如何为 Maven 项目做到这一点.但是 sbt 显然使用了不同的方法.(我知道 Ivy 以某种方式参与其中,但我从未使用过它,也不了解它是如何工作的.)

I've got an sbt (Scala) project that currently pulls artifacts from the web. We'd like to move towards a corporate-standardized Nexus repository that would cache artifacts. From the Nexus documentation, I understand how to do that for Maven projects. But sbt obviously uses a different approach. (I understand Ivy is involved somehow, but I've never used it and don't understand how it works.)

我如何告诉 sbt 和/或底层 Ivy 将企业 Nexus 存储库系统用于所有依赖项?我想要使​​用某种项目级配置文件的答案,以便我们源存储库的新克隆将自动使用代理.(即,在点目录中处理每个用户的配置文件是不可行的.)

How do I tell sbt and/or the underlying Ivy to use the corporate Nexus repository system for all dependencies? I'd like the answer to use some sort of project-level configuration file, so that new clones of our source repository will automatically use the proxy. (I.e., mucking about with per-user config files in a dot-directory is not viable.)

谢谢!

推荐答案

第 1 步:按照 详细主题:代理存储库,我总结并添加到下面:

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

  1. (如果您使用的是 Artifactory,则可以跳过此步骤.)在您的公司 Maven 存储库上创建一个完全独立的 Maven 代理存储库(或组),以代理 ivy-style 存储库,例如这两个重要的存储库:

  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:

这是必需的,因为一些存储库管理器无法处理混合在一起的 Ivy 风格和 Maven 风格的存储库.

This is needed because some repository managers cannot handle Ivy-style and Maven-style repositories being mixed together.

创建一个文件 repositories,列出您的主要公司存储库和您在步骤 1 中创建的任何额外存储库,格式如下:

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]

  • 要么将该文件保存在主目录中的 .sbt 目录中,要么在 sbt 命令行中指定它:

  • Either save that file in the .sbt directory inside your home directory, or specify it on the sbt command line:

    sbt -Dsbt.repository.config=<path-to-your-repo-file>
    

  • 对于使用旧版本 sbt 的人来说是个好消息:尽管至少在 sbt 0.12.0 启动器 jar 中,旧 sbt 版本的启动属性文件不包含所需的行(提到 repository.config 的那个),如果您编辑这些文件以添加所需的行,并将它们重新打包到 sbt 0.12.0 启动器 jar 中,它仍然适用于那些版本的 sbt!这是因为该功能是在启动器中实现的,而不是在 sbt 本身中实现.而且 sbt 0.12.0 启动器号称可以启动所有版本的 sbt,直接回到 0.7!

    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!

    第 2 步:为确保未使用外部存储库,请从解析器中删除默认存储库.这可以通过以下两种方式之一完成:

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

    1. 添加上面详细主题页面中提到的命令行选项 -Dsbt.override.build.repos=true.这将导致您在文件中指定的存储库覆盖在您的任何 sbt 文件中指定的任何存储库.不过,这可能仅适用于 sbt 0.12 及更高版本 - 我还没有尝试过.
    2. 在构建文件中使用 fullResolvers := Seq( resolver(s) for your company maven repositories ),而不是 解析器 ++=resolvers := 或您曾经使用过的任何东西.
    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. 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.

    这篇关于如何让 sbt 使用本地 Maven 代理存储库(Nexus)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆