如何为每个用户或系统范围配置 Ivy 缓存目录?

发布于 2024-09-07 17:12:13 字数 486 浏览 7 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

┾廆蒐ゝ 2024-09-14 17:12:29
sbt -ivy /tmp/.ivy2 compile

参考:man sbt

选项:
-ivy path:本地ivy存储库的路径(默认:~/.ivy2)

sbt -ivy /tmp/.ivy2 compile

Reference: man sbt

Options:
-ivy path: path to local Ivy repository (default: ~/.ivy2)

怪我闹别瞎闹 2024-09-14 17:12:26

要在 SBT 启动期间编辑缓存位置,请参阅 Sbt 启动器配置 官方文档中。

基本上,要使其在系统范围内工作,您必须:

  • 将名为 sbt.boot.properties 的配置文件放在系统范围内可访问的位置(默认文件在链接中列出)多于)。
  • 调用启动器,并将附加系统属性 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:

  • Put a configuration file named sbt.boot.properties somewhere where it's accessible system-wide (the default one is listed at the link above).
  • Call the launcher with the additional system property sbt.boot.properties set to point to your configuration file.
  • Set the 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.

烟花肆意 2024-09-14 17:12:22

您可以使用 Path.userHome.absolutePath 检索主目录,如下所示:

resolvers += Resolver.file("Local", file( Path.userHome.absolutePath + "/.ivy2/local"))(Resolver.ivyStylePatterns)

我想您还可以使用 System.getenv 检索环境变量并以相同的方式连接,如下图所示:

resolvers += Resolver.file("Local", file( System.getenv("IVY_HOME") + "/whatever/it/is"))(Resolver.ivyStylePatterns)

You can retrieve your home directory using Path.userHome.absolutePath, like shown below:

resolvers += Resolver.file("Local", file( Path.userHome.absolutePath + "/.ivy2/local"))(Resolver.ivyStylePatterns)

I suppose that you can also retrieve environment variables using System.getenv and concatenate in the same way, like shown below:

resolvers += Resolver.file("Local", file( System.getenv("IVY_HOME") + "/whatever/it/is"))(Resolver.ivyStylePatterns)
清风疏影 2024-09-14 17:12:20

ivy 文件的位置

我通常将 ivy.xmlivysettings.xml 文件与构建文件放在一起,如下所示:

build.xml
ivy.xml
ivysettings.xml

ivy 任务 resolve 和 < em>retrieve 应该找到这两个文件。

例如:

<target name="init" description="--> retrieve dependencies with ivy">
    <ivy:retrieve pattern="lib/[conf]/[artifact].[ext]"/>
</target>

奇怪,它不适合你。

用户特定设置

您可以通过多种方式模拟 Maven 设置文件

1) 在项目中包含指令 ivysettings.xml

<ivysettings>
    <include file="${user.home}/.ivy2/my-ivysettings.xml"/>
</ivysettings>

2) 从构建文件设置位置

<target name="init" description="--> retrieve dependencies with ivy">
    <ivy:settings file="${user.home}/.ivy2/my-ivysettings.xml" />
    <ivy:retrieve pattern="lib/[conf]/[artifact].[ext]"/>
</target>

3) 我从未尝试过此操作,但我认为您可以使用 ANT 属性覆盖默认位置

ant -Divy.settings.file=$HOME/.ivy2/my-ivysettings.xml

Location of ivy files

I normally put the ivy.xml and ivysettings.xml files alongside by build file as follows:

build.xml
ivy.xml
ivysettings.xml

The ivy tasks resolve and retrieve should find both files.

For example:

<target name="init" description="--> retrieve dependencies with ivy">
    <ivy:retrieve pattern="lib/[conf]/[artifact].[ext]"/>
</target>

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

<ivysettings>
    <include file="${user.home}/.ivy2/my-ivysettings.xml"/>
</ivysettings>

2) Set location from the build file

<target name="init" description="--> retrieve dependencies with ivy">
    <ivy:settings file="${user.home}/.ivy2/my-ivysettings.xml" />
    <ivy:retrieve pattern="lib/[conf]/[artifact].[ext]"/>
</target>

3) I've never tried this but I think you can override the default location using an ANT property

ant -Divy.settings.file=$HOME/.ivy2/my-ivysettings.xml
握住我的手 2024-09-14 17:12:19

如果您还没有这样做,您应该使用 sbt-extras

然后,它只是您传递的一个标志:

sbt -ivy /path/to/.ivy2

You should use sbt-extras if you don't do already.

Then, it's simply a flag you pass it:

sbt -ivy /path/to/.ivy2
飘逸的'云 2024-09-14 17:12:17

您只需将环境变量添加到 sbt 启动 shell 脚本中:

java -Dsbt.ivy.home=/tmp/.ivy2/ ...

请参阅 库管理

You can simply add an environment variable to your sbt launch shell script:

java -Dsbt.ivy.home=/tmp/.ivy2/ ...

See Library Management in the official documentation.

单调的奢华 2024-09-14 17:12:16

sbt.ivy.home 属性只是解决方案的一半。它控制 sbt 启动器下载 sbt 本身(以及相关依赖项,如 scala 编译器和库等)的位置。正如 Joachim Hofer 所指出的,它对项目声明的依赖项的下载位置没有影响。

要更改该位置,您必须设置 ivy.home 属性。因此,为了增强 Joachim 的第一个解决方案,您需要设置两个系统属性:

java -Dsbt.ivy.home=/tmp/.ivy2/ -Divy.home=/tmp/.ivy2/ -jar `dirname $0`/sbt-launch.jar "$@"

使用这些属性,启动器会将您的项目和 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:

java -Dsbt.ivy.home=/tmp/.ivy2/ -Divy.home=/tmp/.ivy2/ -jar `dirname $0`/sbt-launch.jar "$@"

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文