如何让 sbt 使用本地 Maven 代理存储库 (Nexus)?
我有一个 sbt (Scala) 项目,当前从网络中提取工件。我们希望转向企业标准化的 Nexus 存储库来缓存工件。从 Nexus 文档中,我了解了如何为 Maven 项目执行此操作。但 sbt 显然采用了不同的方法。 (我知道 Ivy 以某种方式参与其中,但我从未使用过它,也不明白它是如何工作的。)
我如何告诉 sbt 和/或底层 Ivy 使用企业 Nexus 存储库系统来处理所有依赖项?我希望答案是使用某种项目级配置文件,以便我们源存储库的新克隆将自动使用代理。 (即,在点目录中修改每个用户的配置文件是不可行的。)
谢谢!
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.)
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.)
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
步骤 1:按照详细主题:代理存储库<中的说明进行操作/a>,我已将其总结并添加到下面:
(如果您使用 Artifactory,则可以跳过此步骤。)在您的计算机上创建完全独立的 Maven 代理存储库(或组)企业 Maven 存储库,用于代理常春藤风格存储库,例如这两个重要的存储库:
这是必需的,因为某些存储库管理器无法处理混合在一起的 Ivy 风格和 Maven 风格存储库。
创建一个文件
repositories
,列出您的主要公司存储库以及您在步骤 1 中创建的任何额外存储库,格式如下:<前><代码>[存储库]
my-maven-proxy-releases:http://repo.example.com/maven-releases/
my-ivy-proxy-releases:http://repo.example.com/ivy-releases/,[组织]/[模块]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[修订版]/[类型]s/[工件](-[分类器]).[ext]
保存该文件在主目录中的
.sbt
目录中,或在 sbt 命令行上指定:对于使用旧版本 sbt 的用户来说是个好消息:尽管如此,至少在 sbt 0.12.0 启动器 jar 中,旧 sbt 版本的启动属性文件不包含所需的行(提到
repository.config
的行) ,如果您编辑这些文件以添加所需的行,并将它们重新打包到 sbt 0.12.0 启动器 jar 中,它仍然适用于这些版本的 sbt!这是因为该功能是在启动器中实现的,而不是在 sbt 本身中实现的。 sbt 0.12.0 启动器据称能够启动所有版本的 sbt,甚至可以追溯到 0.7!步骤 2:为了确保不使用外部存储库,请从解析器中删除默认存储库。这可以通过以下两种方式之一完成:
-Dsbt.override.build.repos=true
。这将导致您在文件中指定的存储库覆盖您在任何 sbt 文件中指定的任何存储库。不过,这可能只适用于 sbt 0.12 及更高版本 - 我还没有尝试过。fullResolvers := Seq(
resolver(s) for your enterprise maven repositories)
,而不是resolvers ++ =
或resolvers :=
或您以前使用的任何内容。Step 1: Follow the instructions at Detailed Topics: Proxy Repositories, which I have summarised and added to below:
(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:
This is needed because some repository managers cannot handle Ivy-style and Maven-style repositories being mixed together.
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:Either save that file in the
.sbt
directory inside your home directory, or specify it on the sbt command line: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!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:
-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.fullResolvers := Seq(
resolver(s) for your corporate maven repositories)
in your build files, instead ofresolvers ++=
orresolvers :=
or whatever you used to use.好的,在 sbt 邮件列表上 Mark Harrah 的帮助下,我有了一个可行的答案。
我的构建类现在如下所示(加上一些其他存储库):
现在,如果我从计算机的
.ivy2/cache
目录中删除 Squeryl 树,sbt 会尝试使用以下命令从 Nexus 树中获取它:适当的网址。问题解决了!OK, with some help from Mark Harrah on the sbt mailing list, I have an answer that works.
My build class now looks like the following (plus some other repos):
Now, if I delete the Squeryl tree from my machine's
.ivy2/cache
directory, sbt tries to grab it from the Nexus tree with the appropriate URL. Problem solved!您所需要的只是定义一个属性文件
sbt.boot.properties
,它允许您::此
sbt.boot.properties
文件的灵感来自:sbt-0.74
本身中找到的!我已经注释了任何外部 Maven 存储库定义,并添加了对我自己的 Nexus Maven 存储库的引用。
定义一个 sbt.bat 包装器(为了确保指定您的
sbt.boot.properties
),例如:并且您的 sbt 将仅下载工件 来自:
刚刚在家里用我运行的旧 Nexus 开源 1.6 进行了测试,java 1.6,sbt07.4
这给出了:
如果我在 sbt.boot.properties 文件中尝试一个有趣的值:
所以它确实将自己限制为我定义的两个存储库:
(我评论了其他所有内容:
local
,maven-local
,...)如果我评论所有存储库并输入一个有趣的值(2.7. 9)对于
sbt.boot.properties
中的 scala 版本,我确实得到(就像OP所做的那样)如果我输入 2.7.7 (同时仍然有all repo注释),是的,它不会生成错误:
但这只是因为在我之前的尝试中它已经下载了 scala2.8.0。
如果我从我的
project/boot
目录中删除该库,那么它将抛出异常:All you need is to define a property file
sbt.boot.properties
which will allow you to:Note: this
sbt.boot.properties
file is inspired from:sbt-0.74
itself!I have commented any external Maven repository definition, and added a reference to my own Nexus Maven repo.
Define a sbt.bat wrapper (in order to be sure to specify your
sbt.boot.properties
) like:And your sbt will download artifacts only from:
Just tested at home with an old Nexus opensource 1.6 I had running, java 1.6, sbt07.4
That gives:
If I try a funny value in the sbt.boot.properties file:
So it does limit itself to the two repo I defined:
(I commented everything else:
local
,maven-local
, ...)If I comment all repositories and put a funny value (2.7.9) for the scala version in the
sbt.boot.properties
, I do get (like the OP did)If I put 2.7.7 (while still having all repo commented), yes, it won't generate an error:
But that's only because it already had downloaded scala2.8.0 during my previous tries.
If I remove that library from my
project/boot
directory, then it will throw an Exception:编辑 sbt_home/conf 中的配置文件“sbtconfig.txt”
添加两行
repo.properties 内容是
edit the config file in sbt_home/conf "sbtconfig.txt"
add two line
the repo.properties content is
嗯,这困扰了我一段时间,所以我发现一个人在 github 上为 Maven 编写了一个 SBT 插件,名为 maven-sbt 因此,您所要做的就是将其包含在您的插件项目中,并使您的项目与 maven.MavenDependency 混合,并且所有操作(例如更新和发布本地)都与本地 maven 一起工作。这样做的好处是,如果您像我一样,您的组织都是专家。所以,所有的库都在本地 Maven 存储库中,但如果由于某种原因你首先使用 sbt 构建,那么你也会开始在 ivy 中得到一堆或 jars。这是多么浪费空间和时间,因为您仍然需要为您的 Maven 构建获取它们。
也就是说,我希望将其内置到 sbt 中,这样我就不需要将其添加到每个项目中。也许至少作为一个处理器。我读到他在一件事中提到他想将其添加到 0.9,但我一直找不到它。
Well this has bugged me for a while so I found a guy that has written an SBT plugin for maven out on github called maven-sbt so all you have to do is include it in your plugins project and make your project mixin with maven.MavenDependencies and all your operations like update and publish-local work with your local maven. The nice thing about that is if you are like me, your org is all maven. So, all you libs are in you local maven repo but if for some reason you build with sbt first, then you start getting a bunch or jars in ivy too. What a waste of space, and time since you will still need to get them for your maven builds.
That said, I wish this were built into sbt so I would not need to add it to every project. Maybe as a processor at least. He mentioned in one thing I read that he would like to add it to 0.9 but I have not been able to find it.
我收到此错误是因为
~/.sbt/repositories
中有一个空白文件。将存储库添加到文件和删除文件都解决了问题。I got this error because I had a blank file in
~/.sbt/repositories
. Both adding repositories to the file and removing the file solved the problem.