Maven-备用.m2目录 [英] Maven - alternative .m2 directory

查看:68
本文介绍了Maven-备用.m2目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何全局更改Maven的.m2目录的位置?

Maven使用${user.home}/.m2进行设置,存储库缓存等.

我知道我可以做到

  • 指向存储库缓存的其他目录(通过更改全局配置文件中的localRepository属性),而不指向其他任何目录(例如,settings.xml).
  • 使用-s CLI选项,但是每次使用maven时都必须这样做.

但理想情况下,我想要一个全局解决方案.凭直觉,这应该是可能的.

我想这样做是因为我的公司将我的$ {user.home}设置为容易出现网络问题的共享驱动器.

解决方案

使用MAVEN_OPTS环境变量设置存储库的位置.在启动外壳程序时进行设置,而不必每次都将其放在命令行中.

export MAVEN_OPTS="-Dmaven.repo.local=/path/to/repository"

您说过要更改settings.xml文件和repository目录的.m2.您要设置M2_HOME环境变量. Maven设置文档说,它可以控制Maven在何处查找settings.xml.从那里,您可以控制存储库的位置,等等.

How do I globally change the location of maven's .m2 directory?

Maven uses ${user.home}/.m2 for it's settings, repository cache, etc.

I know that I can:

  • point to a different dir for the repository cache (by changing the localRepository attribute in my global config file), but not for anything else (settings.xml, for instance).
  • Use the -s CLI option, but I'd have to do that every time I use maven.

But ideally, I'd like a global solution. Intuitively that should be possible..

I'd like to do this because my company sets my ${user.home} to a shared drive which is prone to network issues.

解决方案

Use the MAVEN_OPTS environment variable to set the location of your repository. Set it in your shell startup, and you don't have to put it on the command line every time.

export MAVEN_OPTS="-Dmaven.repo.local=/path/to/repository"

You said you wanted to change the .m2 for the settings.xml file as well as the repository directory. You want to set the M2_HOME environment variable. The Maven settings documentation says that it controls where Maven looks for settings.xml. From there, you can control the repository location, etc.

这篇关于Maven-备用.m2目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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