Following previous Maven article, we will go through more Maven concepts such as Maven Repositories, Plug-ins to understand better Maven standards.
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:
false central Central Repository http://repo.maven.apache.org/maven2
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 http://repo.maven.apache.org/maven2
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 (download.grokonez.com for example):
com.grokonez.common-lib common-lib 0.0.1 javasampleapproach.lib1 http://download.grokonez.com/maven2/lib1 javasampleapproach.lib2 http://download.grokonez.com/maven2/lib2
Return to Effective POM tab of our project pom.xml:
maven-antrun-plugin 1.3 maven-assembly-plugin 2.2-beta-5 maven-dependency-plugin 2.8 maven-release-plugin 2.3.2 maven-clean-plugin 2.5 maven-resources-plugin 2.6 maven-jar-plugin 2.4 maven-compiler-plugin 3.1 maven-surefire-plugin 2.12.4 maven-install-plugin 2.4 maven-deploy-plugin 2.7 maven-site-plugin 3.3
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 http://maven.apache.org/plugins/index.html for all plug-ins supported by Maven Project.
In next article, we will dive into another Maven’s important concept: Dependencies.
Last updated on December 10, 2017.