如何为每个用户或系统范围配置 Ivy 缓存目录?
我使用 SBT 作为构建 Scala 项目的构建工具。
我的问题是,我无法配置 SBT 将依赖项下载到我的用户主目录。因此,我正在寻找每个用户甚至更好的系统范围设置来告诉 SBT 将 Ivy 缓存目录放在其他地方。
对于 Maven,每个用户的 settings.xml 可用于配置本地存储库。
我已阅读问题如何覆盖 Ivy 缓存的位置? 和它的答案,但它似乎只描述了如何在每个项目的基础上配置设置。
如果没有其他选择,我会选择每个项目设置,但我没有从上述问题中得到答案。我们欢迎更多详细信息,例如将 ivysettings.xml 放在哪里。我把它放到项目根目录下,还是不行。
I am using SBT as my build tool for building a Scala project.
My problem is, I can't configure SBT to download dependencies to my user home directory. Therefore I am looking for a per-user or even better a system-wide setting to tell SBT to put the Ivy cache directory somewhere else.
With maven there is the per-user settings.xml that can be used to configure the local repository.
I have read question How to override the location of Ivy’s Cache? and it's answers, but it seems it only describes how to configure the setting on a per project basis.
If there is no alternative I would go for a per-project setting, but I didn't get the answer from the mentioned question to work. Some more details would be most welcome, for example where to put the ivysettings.xml. I put it into the project's root directory and it didn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
参考:man sbt
Reference: man sbt
要在 SBT 启动期间编辑缓存位置,请参阅 Sbt 启动器配置 官方文档中。
基本上,要使其在系统范围内工作,您必须:
sbt.boot.properties
设置为指向您的配置文件。cache-directory
条目(在[ivy]
部分中)设置为 ivy 缓存的位置。但不幸的是,这种配置似乎并没有延续到正常的 SBT 使用中。
For editing the cache location during the SBT boot itself, see Sbt Launcher Configuration in the official documentation.
Basically, to get it to work system-wide, you'd have to:
sbt.boot.properties
somewhere where it's accessible system-wide (the default one is listed at the link above).sbt.boot.properties
set to point to your configuration file.cache-directory
entry (in the[ivy]
section) to the location of your ivy cache.This configuration doesn't seem to carry over to normal SBT usage, though, unfortunately.
您可以使用 Path.userHome.absolutePath 检索主目录,如下所示:
我想您还可以使用 System.getenv 检索环境变量并以相同的方式连接,如下图所示:
You can retrieve your home directory using
Path.userHome.absolutePath
, like shown below:I suppose that you can also retrieve environment variables using
System.getenv
and concatenate in the same way, like shown below:ivy 文件的位置
我通常将 ivy.xml 和 ivysettings.xml 文件与构建文件放在一起,如下所示:
ivy 任务 resolve 和 < em>retrieve 应该找到这两个文件。
例如:
奇怪,它不适合你。
用户特定设置
您可以通过多种方式模拟 Maven 设置文件
1) 在项目中包含指令 ivysettings.xml
2) 从构建文件设置位置
3) 我从未尝试过此操作,但我认为您可以使用 ANT 属性覆盖默认位置
Location of ivy files
I normally put the ivy.xml and ivysettings.xml files alongside by build file as follows:
The ivy tasks resolve and retrieve should find both files.
For example:
Odd, that it's not working for you.
User specific settings
You can emulate the maven settings file in a couple of ways
1) include directive within the project ivysettings.xml
2) Set location from the build file
3) I've never tried this but I think you can override the default location using an ANT property
如果您还没有这样做,您应该使用 sbt-extras 。
然后,它只是您传递的一个标志:
You should use sbt-extras if you don't do already.
Then, it's simply a flag you pass it:
您只需将环境变量添加到 sbt 启动 shell 脚本中:
请参阅 库管理。
You can simply add an environment variable to your sbt launch shell script:
See Library Management in the official documentation.
sbt.ivy.home
属性只是解决方案的一半。它控制 sbt 启动器下载 sbt 本身(以及相关依赖项,如 scala 编译器和库等)的位置。正如 Joachim Hofer 所指出的,它对项目声明的依赖项的下载位置没有影响。要更改该位置,您必须设置 ivy.home 属性。因此,为了增强 Joachim 的第一个解决方案,您需要设置两个系统属性:
使用这些属性,启动器会将您的项目和 sbt 的依赖项下载到
/tmp/.ivy2/
目录。当然,您也可以将它们放在单独的目录中。The
sbt.ivy.home
property is only half of the solution. It controls where the sbt launcher downloads sbt itself (and related dependencies like the scala compiler and library, etc.) As noted by Joachim Hofer, it has no effect on where the dependencies declared by your project get downloaded.To change that location, you must set the
ivy.home
property. So, to augment Joachim's first solution, you would set both system properties:With these properties, the launcher will download both your project's and sbt's dependencies to the
/tmp/.ivy2/
directory. Of course, you can put them in separate directories as well.