How to move maven directory .m2 from my home directory after installing IntelliJ
You can modify the location of the Maven local repository by modifying the Maven settings. From Configuring your Local Repository:
The location of your local repository can be changed in your user configuration. The default value is
${user.home}/.m2/repository/
.<settings>
...
<localRepository>/path/to/local/repo/</localRepository>
...
</settings>
Note: The local repository must be an absolute path.
Since you are using the Maven installation that is shipped with IntelliJ and not your own Maven version, you can create a Maven user settings:
- Create a file
settings.xml
under${user.home}/.m2/
Have the following content in it:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>/path/to/local/repo</localRepository>
</settings>
Maven will read this file and use the specified local repository.
Why can't I find my settings.xml under ~/.m2?
There are two locations where a settings.xml file may live:
The Maven install: ${maven.home}/conf/settings.xml
The user’s install: ${user.home}/.m2/settings.xml
The former settings.xml are also called global settings, the latter
settings.xml are referred to as user settings. If both files exists,
their contents gets merged, with the user-specific settings.xml being
dominant.Tip: If you need to create user-specific settings from scratch, it’s
easiest to copy the global settings from your Maven installation to
your ${user.home}/.m2 directory. Maven’s default settings.xml is a
template with comments and examples so you can quickly tweak it to
match your needs.
Maven Settings Reference Guide
So simply
- navigate to your maven directory under
${maven.home}/conf/settings.xml
- and copy&paste your settings.xml to
${user.home}/.m2/
How do I find out which settings.xml file maven is using
Use the Maven debug option, ie mvn -X
:
Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
Maven home: /usr/java/apache-maven-3.0.3
Java version: 1.6.0_12, vendor: Sun Microsystems Inc.
Java home: /usr/java/jdk1.6.0_12/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-32-generic", arch: "i386", family: "unix"
[INFO] Error stacktraces are turned on.
[DEBUG] Reading global settings from /usr/java/apache-maven-3.0.3/conf/settings.xml
[DEBUG] Reading user settings from /home/myhome/.m2/settings.xml
...
In this output, you can see that the settings.xml is loaded from /home/myhome/.m2/settings.xml
.
Why maven settings.xml file is not there?
settings.xml
is not required (and thus not autocreated in ~/.m2 folder) unless you want to change the default settings.
Standalone maven and the maven in eclipse will use the same local repository (~/.m2 folder). This means if some artifacts/dependencies are downloaded by standalone maven, it will not be again downloaded by maven in eclipse.
Based on the version of Eclipse that you use, you may have different maven version in eclipse compared to the standalone. It should not matter in most cases.
Which folder does the Maven settings.xml file belong in?
Both answers are correct.
Basic config file for maven is inside mvn/conf/settings
and you could add some configuration (or override basic config) with your personal maven settings file located in ~.m2/settings.xml
How to specify an alternate location for the .m2 folder or settings.xml permanently?
You need to add this line into your settings.xml
(or uncomment if it's already there).
<localRepository>C:\Users\me\.m2\repo</localRepository>
Also it's possible to run your commands with mvn clean install -gs C:\Users\me\.m2\settings.xml
- this parameter will force maven to use different settings.xml
then the default one (which is in $HOME/.m2/settings.xml
)
Related Topics
How to Return an Array from Jni to Java
Using Static Variables in Android
Differencebetween List and Arraylist
Custom Listview Click Issue on Items in Android
Android: How to Get the Current Day of the Week (Monday, etc...) in the User's Language
How Delete a Collection or Subcollection from Firestore
Foreign Key Constraints in Android Using SQLite? on Delete Cascade
Service Discovery Failed Exception Using Bluetooth on Android
Sqlite in Android How to Update a Specific Row
Understand the R Class in Android
What Could Be Reason for "Prism-Es2 Error:Gl_Version (Major.Minor) = 1.4"
Running a Scheduled Task Written in Java on a Linux Server
Using Xdg Directory Specification on Java Application
Cmake Can't Find Java, But It's Installed
How to Install Java Application to My Linux System
Exception While Submitting a Mapreduce Job from Remote System
Is the Order of Values Retrieved from a Hashmap the Insertion Order