Maven Introduction – Part 2: Maven Repositories and Plugins

Following previous Maven article, we will go through more Maven concepts such as Maven Repositories, Plug-ins to understand better Maven standards.

I. Repositories

A Repository is a directory or a place to store project jars, library jar, plugins… for Maven to use easily.
We have 3 kinds of Repository: local, central and remote.

1. Local Repository

Local Repository is a local folder which stores all our project’s dependencies (library jars, plugin jars and other downloaded files). When you run a Maven build, all Maven dependency jars are automatically downloaded into Local Repository.

By default, it is created by Maven in %USER_HOME% directory.
In Eclipse, we can check it easily by Window -> Preferences -> Maven -> User Settings:

It is .m2/repository folder and this is how it looks like:

But, if we wanna override the default location, we just add this code to .m2/settings.xml (open it by click open file)

2. Central Repository

Now return to Effective POM tab of our project pom.xml, we will see:

This is Maven Central Repository which is provided by Maven community, contains lots of common libraries.
When building Maven project, firstly, Maven gets the dependency from local repository. If not found, Maven get it from default Maven central repository

3. Remote Repository

If Maven does not find the required dependency in Central Repository, we need to add some Remote Repositories to download the libraries from another location instead of Central Repository.

The code shows how to get required libraries from another source ( for example):

II. Plug-ins

Return to Effective POM tab of our project pom.xml:

We can see that all Maven plug-ins are inside build tag, it is because building is the key function of Maven and Maven is a plugin execution framework – all tasks is done by plug-ins.

These Maven plug-ins are commonly used to create jar and war files, compile code files, unit testing, create project documentation and reports.

There are 2 kinds of plug-ins:
Build plug-ins are executed during the build and they should be configured in build element of POM.
Reporting plug-ins are executed during the site generation and they should be configured in reporting element of POM.

Some remarkable plug-ins:
maven-compiler-plugin is a Maven core plug-in. The core plug-ins’ goals are triggered on Maven core phases (clean, compile, test…). Non-core plug-ins relate to packaging, reporting, utilities…

maven-surefire-plugin is also a Maven core plug-in and its goal is surefire:test. It is as part of default life cycle (the test phase) to run unit tests. It generates reports (*.txt or *.xml).

maven-war-plugin is used to redefine in web POMs. We have again overridden the default behaviour of this plugin that is used to package web modules. This is definitely necessary if you have a non-Maven standard project structure. Filtering, moving web resources around, and managing the generated war is the purpose of this plugin.

Please read for all plug-ins supported by Maven Project.

In next article, we will dive into another Maven’s important concept: Dependencies.

By grokonez | November 17, 2016.

Last updated on December 10, 2017.

Related Posts

Got Something To Say:

Your email address will not be published. Required fields are marked *