Settings in Maven

Maven settings can be specified in 2 files.
  • User settings file - ~/.m2/settings.xml
  • Maven global settings file - maven_home/conf/settings.xml
Now let us discuss what kind of settings can be configured for maven.

Repository Path

Default repository path is ~/.m2/repository But you can change is using below tag in settings.xml
 
<localRepository>local_repository_path</localRepository>

Interactive mode

Maven interactive mode is true by default. But you change it to false using below tag in settings.xml
 
<interactiveMode>false</interactiveMode>

Offline mode

Offline mode – It is false by default. But you can change it using below tag.
 
<offline>true</offline>

Proxy settings

As you know that maven downloads the libraries from internet, you will have to provide proxy settings in case you are behind proxy.
 
<proxies>
<proxy>
<id>p1</id>
<active>true</active>
<protocol>http</protocol>
<username>user</username>
<password>password</password>
<host>proxy-server-name</host>
<port>80</port>
<nonProxyHosts>exclude.in|abc.com</nonProxyHosts>
</proxy>
</proxies>

Server authentication settings

You can use servers tag to store the authentication information of the servers used by maven
 
<servers>
<server>
<id>repo1</id>
<username>repo1user</username>
<password>repo1password</password>
</server>
<server>
<!–
more server configuration
–>
</server>
</servers>

Mirror settings

Sometimes the repository used by maven can not serve the requests due to heavy load. So in such situations, we can use mirrors of that particular repositories to download resources.
 
<mirrors>
<mirror>
<id>mirrorId</id>
<mirrorOf>repo1</mirrorOf>
<name>Mirror Name</name>
<url>https://mirrored_repo1.com.au</url>
</mirror>
</mirrors>

Profiles settings

You can also use profiles so that different settings are used in different conditions. For example – You can create a OS specific profile. Certain tasks are dependent on OS type. So depending upon OS type, specific profile is activated.
 
<profiles>
<profile>
<id>windows-profile</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
</profile>

<profile>
<id>unix-profile</id>
<activation>
<os>
<family>unix</family>
</os>
</activation>
</profile>
</profiles>
Complex problems, Simple Solutions