简体   繁体   English

Maven不在由settings.xml中的localRepository指定的目录中存储工件

[英]Maven not storing artifacts in the directory specified by localRepository in settings.xml

I am using apache-maven-3.2.3 我正在使用apache-maven-3.2.3

It is located at C:\\java\\apache-maven-3.2.3 它位于C:\\ java \\ apache-maven-3.2.3

The settings.xml file is located C:\\java\\apache-maven-3.2.3\\conf\\settings.xml settings.xml文件位于C:\\ java \\ apache-maven-3.2.3 \\ conf \\ settings.xml

Inside that settings.xml file, I have the following defined: 在该settings.xml文件中,我定义了以下内容:

<localRepository>C:/java/maven_repo</localRepository>

I have windows environment variables defined: 我定义了Windows环境变量:

  • M2_HOME=C:\\java\\apache-maven-3.2.3 M2_HOME = C:\\ java \\ apache-maven-3.2.3
  • M2=%M2_HOME%\\bin M2 =%M2_HOME%\\ bin
  • PATH environment variable includes %M2% PATH环境变量包括%M2%

I have configures my STS (Eclipse) to use the external Maven installation at C:\\java\\apache-maven-3.2.3 我已经将STS(Eclipse)配置为在C:\\ java \\ apache-maven-3.2.3使用外部Maven安装

My STS Maven-->Installations shows that the global settings are: C:\\java\\apache-maven-3.2.3\\conf\\settings.xml 我的STS Maven->安装显示全局设置为:C:\\ java \\ apache-maven-3.2.3 \\ conf \\ settings.xml

My STS Maven-->User Settings shows that the local repository from merged and global settings is: C:\\java\\maven_repo 我的STS Maven->用户设置显示合并和全局设置中的本地存储库为:C:\\ java \\ maven_repo

There is NO settings.xml at C:/Users/[myuser]/.m2 C:/ Users / [myuser] /。m2处没有settings.xml

In fact, I remove the entire .m2 folder at C:/Users/[myuser]/.m2 to be sure 事实上,我删除了整个C./Users/[myuser]/.m2中的.m2文件夹,以确保

However , When I do a Maven update through STS, it is still downloading artifacts to the default .m2 directory at: C:/Users/[myuser]/.m2/repository 但是 ,当我通过STS进行Maven更新时,它仍将工件下载到默认的.m2目录,位于:C:/ Users / [myuser] /。m2 / repository

My Eclipse project is also showing the Maven Dependencies are found in C:/Users/[myuser]/.m2/repository 我的Eclipse项目还显示可以在C:/ Users / [myuser] /。m2 / repository中找到Maven依赖关系

Can anyone tell me why? 谁能告诉我为什么? What have I done wrong? 我做错了什么? Why wont it use the local repository at c:/java/maven_repo ? 为什么不使用位于c:/ java / maven_repo的本地存储库?

Normally, I will change the default local repository folder from default .m2 to another more meaningful name, for example, maven-repo . 通常,我会将默认的本地存储库文件夹从默认的.m2更改为另一个更有意义的名称,例如maven-repo


Find {M2_HOME}\\conf\\setting.xml , update localRepository to something else. 找到{M2_HOME} \\ conf \\ setting.xml ,将localRepository更新为其他内容。

  <settings>
      <!-- localRepository
       | The path to the local repository maven will use to store artifacts.
       |
       | Default: ~/.m2/repository
      <localRepository>/path/to/local/repo</localRepository>
      -->

    <localRepository>D:/maven_repo</localRepository>


Done, your new Maven local repository is now changed to D:/maven_repo. 完成后,新的Maven本地存储库现在更改为D:/ maven_repo。

The only way I have managed to get this to work in Eclipse is to also set the user settings file in Window-->Preferences-->Maven-->User Settings to the same as the global settings: C:\\java\\apache-maven-3.2.3\\conf\\settings.xml 我设法使它在Eclipse中工作的唯一方法是还将Window-> Preferences-> Maven-> User Settings中的用户设置文件设置为与全局设置相同的文件:C:\\ java \\ apache -maven-3.2.3 \\ conf \\ settings.xml

But I would imagine that leaving that field blank should take the settings from the global settings.xml, but for some reason it doesn't. 但是我可以想象将该字段保留为空白应该从全局settings.xml中获取设置,但是由于某些原因却没有。 So if I leave that user settings field blank, the localRepositorty from global settings.xml does not apply. 因此,如果我将该用户设置字段保留为空白,则来自全局settings.xml的localRepositorty不适用。

However, if I run Maven outside eclipse, it works as expected. 但是,如果我在eclipse之外运行Maven,它会按预期工作。

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

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