Apache Maven Setup

If you are working behind a proxy server, then you will need to configure Maven to use the proxy server. Naturally you will need to do this before using Maven as it needs to connect to Maven Central to do anything! So, I would suggest you start with a settings.xml file something like this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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">

  <proxies>
    <proxy>
      <id>the_proxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>127.0.0.1</host>
      <port>8080</port>
      <username>proxyuser</username>
      <password>somepassword</password>
      <nonProxyHosts>*.google.com|example.com</nonProxyHosts>
    </proxy>
  </proxies>

</settings>
The settings.xml file should be located in your .m2 directory, which is in your "home" directory. The username, password and nonProxyHosts do not have to be used. Even though this is for http it covers https as well, which is nice.

Setting Up

When starting with Maven it makes sense to use the directory structure that Maven expects, so read Maven – Introduction to the Standard Directory Layout and run with that.

Encoding

If you don't specifically set this you will see warning messages, so add the following into your POM file as a child of the project element:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

Encrypting Passwords

There is a good article on this at Maven Tips and Tricks: Encrypting Passwords however the key is using mvn --encrypt-master-password and mvn --encrypt-password, which can be abbreviated to "-emp" and "-ep" respectively. If you have trouble with your password as it contains non alphanumeric characters then on Linux/macOS surround your password with single quotes and on Windows use double quotes.