Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we Change Maven default Directory(.m2) Name?

As we know Maven Downloaded all Jars from repository to local machine in a default directory name .m2 and location of this directory in Windows machine(Inside User Folder) Or in Home directory in case of Linux machine. Now my question is that can we change the name of .m2 to myjars or some other name?

like image 531
Subodh Joshi Avatar asked Mar 20 '13 06:03

Subodh Joshi


People also ask

What is the default location of local repository in Maven?

The location of your local repository can be changed in your user configuration. The default value is ${user. home}/. m2/repository/ .

What is .m2 folder in Maven?

m2 folder is the default folder used by maven to store its: settings. xml file which specifies properties, like the central repository to download your dependencies, the location of the so-called localRepository. by default, the localRepository in which maven stores all the dependencies your project might need to run.

Can we create .m2 folder manually?

m2 folder will not be present in C:\Users\ {user} path. To generate the folder you have to run any maven command e.g. mvn clean, mvn install etc. so that it searches for settings.


2 Answers

YES:

<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
                  http://maven.apache.org/xsd/settings-1.0.0.xsd">
   <localRepository>${user.home}/.m2/repository</localRepository>
   <interactiveMode>true</interactiveMode>
   <usePluginRegistry>false</usePluginRegistry>
   <offline>false</offline>
   ...
 </settings>
  • localRepository: This value is the path of this build system's local repository. The default value is ${user.home}/.m2/repository. This element is especially useful for a main build server allowing all logged-in users to build from a common local repository.

  • interactiveMode: true if Maven should attempt to interact with the user for input, false if not. Defaults to true.

  • usePluginRegistry: true if Maven should use the ${user.home}/.m2/plugin-registry.xml file to manage plugin versions, defaults to false. Note that for the current version of Maven 2.0, the plugin-registry.xml file should not be depended upon. Consider it dormant for now.

  • offline: true if this build system should operate in offline mode, defaults to false. This element is useful for build servers which cannot connect to a remote repository, either because of network setup or security reasons.

like image 199
lichengwu Avatar answered Oct 20 '22 19:10

lichengwu


Yes, you can do that. But make sure, you make the appropriate path change in the <localRepository> of your settings.xml present in the conf folder of maven home directory.

like image 3
Rahul Avatar answered Oct 20 '22 18:10

Rahul