dleerob
dleerob

Reputation: 5371

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

I am using apache-maven-3.2.3

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

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

Inside that settings.xml file, I have the following defined:

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

I have windows environment variables defined:

  • M2_HOME=C:\java\apache-maven-3.2.3
  • M2=%M2_HOME%\bin
  • PATH environment variable includes %M2%

I have configures my STS (Eclipse) to use the external Maven installation at C:\java\apache-maven-3.2.3

My STS Maven-->Installations shows that the global settings are: 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

There is NO settings.xml at C:/Users/[myuser]/.m2

In fact, I remove the entire .m2 folder at C:/Users/[myuser]/.m2 to be sure

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

My Eclipse project is also showing the Maven Dependencies are found in C:/Users/[myuser]/.m2/repository

Can anyone tell me why? What have I done wrong? Why wont it use the local repository at c:/java/maven_repo ?

Upvotes: 0

Views: 1161

Answers (2)

dleerob
dleerob

Reputation: 5371

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

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. So if I leave that user settings field blank, the localRepositorty from global settings.xml does not apply.

However, if I run Maven outside eclipse, it works as expected.

Upvotes: 0

Tnadev
Tnadev

Reputation: 10112

Normally, I will change the default local repository folder from default .m2 to another more meaningful name, for example, maven-repo.


Find {M2_HOME}\conf\setting.xml, update localRepository to something else.

  <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.

Upvotes: 0

Related Questions