My local maven repo is here /Users/power/.m2/repository
.
But I got this error
[java] [ERROR] Could not create local repository at /var/root/.m2/repository -> [Help 1]
Seems Maven thinks that it should use a root user repo. How can I fix it? I don't need to run my maven tasks using root permissions.
1.1 If the default .m2is unable to find, maybe someone changed the default path. Issue the following command to find out where is the Maven local repository: mvn help:evaluate -Dexpression=settings.localRepository
Usually, this directory is named .m2. Here's where the default local repository is located based on OS: Windows: C:\Users\<User_Name>\.m2 Linux: /home/<User_Name>/.m2 Mac: /Users/<user_name>/.m2. And of course, for Linux and Mac, we can write in the short form: ~/.m2 3. Custom Local Repository in settings.xml
Local – Folder location on the local Dev machine Central – Repository provided by Maven community Let's now focus on the local repository. 2. The Local Repository The local repository of Maven is a directory on the local machine, where all the project artifacts are stored.
Each IDE has a separate process to change the local repository path and that you can read its official documentation. For example in Eclipse and STS ( Spring Tools Suite ), we can change the local repository path in the following location: Windows -> Pfreferences -> Maven -> User Settings
Deleting the .m2
folder manually helps sometimes
Your .m2
folder might be corrupted and it doesn't permit you to create new or replace existing with new .m2
folder, so delete the existing .m2
folder manually by entering the below commands.
To view the existing .m2
folder
ls -ltra
To Delete it manually
sudo rm .m2
The default maven repository is
${user.home}/.m2/repository/
but you can use settings.xml ( ${user.home}/.m2/settings.xml
) to change it to a folder that you have permissions on. Or conf/settings.xml in the ${MAVEN_HOME} and change:
<settings>
...
<localRepository>/path/to/local/repo/</localRepository>
...
</settings>
Ideally, you should run maven as yourself and not root to make sure you have permissions or doing 'ksu' first and then use command line.
This error can occur if there is a file called .m2. (Most probably created mistakenly. This happened to me when I copied settings.xml as .m2) If you can delete this and run mvn command again it will create the .m2 folder and you can proceed without a hassel.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With