简体   繁体   English

为什么 maven 使用 settings.xml 中未配置的目录中的本地存储库

[英]Why the maven uses the local repository in directory which is not configured in settings.xml

I saw a weird behavior when I build using maven.当我使用 maven 构建时,我看到了一个奇怪的行为。 I found the maven is using the local repo in a directory which is different from what I configured in settings.xml.我发现 maven 在一个目录中使用本地 repo,这与我在 settings.xml 中配置的不同。 Even worse, I don't know where the directory that maven is using comes from.更糟糕的是,我不知道 maven 使用的目录来自哪里。 To investigate, I have enabled -X when I execute the maven cmd, and I can see the setting.xml is used and the local repo directory.为了调查,我在执行 maven cmd 时启用了 -X,我可以看到使用了 setting.xml 和本地 repo 目录。 I can see the settings.xml (global and user) are the ones I configured.我可以看到 settings.xml (全局和用户)是我配置的。 And the local repo directory is totally different from what I configured in tag (only configured in the user settings.xml).而且本地repo目录和我在tag中配置的完全不同(只在用户settings.xml中配置)。

I can't figure out why.我不明白为什么。 Anyone has idea?有人有想法吗? Is there anyother config file that maven will check to overwrite the localRepository config in settings.xml? maven 是否会检查其他任何配置文件以覆盖 settings.xml 中的 localRepository 配置?

Thanks in advance.提前致谢。

Since you're sure about your global and user settings file, then the local repo could be overriden by the system/user property "maven.repo.local" this can be specified in multiple ways :由于您确定您的全局和用户设置文件,那么本地存储库可以被系统/用户属性“maven.repo.local”覆盖,这可以通过多种方式指定:

  1. as user property : from maven cli like mvn -Dmaven.repo.local= ...作为用户属性:来自 maven cli,如 mvn -Dmaven.repo.local= ...

  2. as system property : when set in MAVEN_OPTS like -Dmaven.repo.local= (it can be set in your maven.bat or maven.sh)作为系统属性:在 MAVEN_OPTS 中设置时,如 -Dmaven.repo.local=(它可以在您的 maven.bat 或 maven.sh 中设置)

if maven.repo.local is not set as user or system property, then maven will look to localRepository config in user settings first then in global settings : if you specify a relative path in localRepository (repo/dir1) then the repo directory will be created under your project directory with the specified path if no option is avilable it uses the path /.m2/repository如果 maven.repo.local 未设置为用户或系统属性,则 maven 将首先在用户设置中查找 localRepository 配置,然后在全局设置中查找:如果您在 localRepository (repo/dir1) 中指定相对路径,则 repo 目录将是在您的项目目录下使用指定的路径创建,如果没有可用的选项,它使用路径 /.m2/repository

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM