Talking about settings.xml file in Apache Maven – Part 2

In the previous tutorial, I showed you some of the basic configurations in the Apache Maven settings.xml file with <localRepository />, <interactiveMode />, <offline />, <pluginGroups />, <proxies /> tags. In this tutorial, we will learn more about some of the more important parts of the Apache Maven configuration file using the <profiles />, <mirrors />, <servers />, <activeProfiles />.

The first is the <profiles> tag.

This tag will contain many <profile> tags that allow us to define many different profiles.

For example:

For each profile, we need to define a unique id to distinguish it from other profiles by using the <id> tag inside this tag. The <profile> tag will also contain some child tags:

  • <activation>

This will decide whether this profile is used by default when we run the Apache Maven command. To do this, we need to declare the <activeByDefault> tag inside this <activation> tag, the value of <activeByDefault> will be true or false and this value will determine whether this profile is used or not?

  • <repositories>

This tab is used to configure the information about the Maven Repository contains the dependencies that you need to use in your projects. Each Maven Repository will be declared with a <repository> tag inside this <repositories> tag. The information of the Maven Repository will be configured through the <id>, <name>, <url> tags as you see in the example above. <layout> means that we will use the Apache Maven standard format.

Please refer to the tutorial Create Maven Repository in Nexus Repository Manager to learn how to create a new Maven Repository for yourself.

  • <pluginRepositories>

This tag is similar to the <repositories> tag, which will contain <pluginRepository> tags that define the Maven Repository that contains the plugins that you need to use in your projects. We also have information on <id>, <name>, <url> that needs to be configured for the <pluginRepository> section.

  • <properties>

This tag is not in the example above but if you need to predefine some properties to use in your Maven projects then please declare this tag. It’s the same as when we declare the <properties> tag in the pom.xml file. 🙂

Next, we’ll look at the <mirrors> tag

This tag is used to declare the Maven Repository can replace the Maven Repository we have declared in the <repository> or <pluginRepository> tag.

For example:

We can declare many <mirror> tags within the <mirrors> tag. The information for each <mirror> is the same as when we declared the <repository> or <pluginRepository> tags, only one more tag to specify which Maven Repository will be replaced with the Maven Repository declared in this <mirror> tag. This is the <mirrorOf> tag.

In the example above, I declare the id of the repository in the example of the <profiles> tag: huongdanjava-releases, will have the mirror of the repository huongdanjava-releases-mirror.

Next, we’ll look at the <servers> tag.

This tab helps us to declare username and password information for the Maven Repository when the use of this Maven Repository needs to be logged.

It will consist of one or more <server> tags, for example:

We use the <username>, <password> tags to declare the username, password, and <id> tags to declare the id of the Maven Repository we need to use this username and password.

Finally, the <activeProfiles /> tag.

This tab helps us define the profiles we need to use by default.

For example:

The value of the <activeProfile> tag will be the id of one profile!

Add Comment