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

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

问题描述

我有一个sbt(Scala)项目,该项目目前正在从网络上提取工件.我们希望转向可缓存工件的公司标准化Nexus存储库.从Nexus文档中,我了解了如何对Maven项目执行此操作.但是sbt显然使用了不同的方法. (我了解常春藤以某种方式参与其中,但我从未使用过它,也不了解它是如何工作的.)

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样式的存储库,例如这两个重要的存储库:

  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/

这是必需的,因为某些存储库管理器无法处理混合在一起的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( 解析程序作为公司Maven存储库 ),而不是resolvers ++=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天全站免登陆